powerpivots

Forum home » Delegate support and help forum » Microsoft Excel Training and help » Powerpivots

Powerpivots

resolvedResolved · Urgent Priority · Version 2013

Lloyd has attended:
Excel PowerPivot course

Powerpivots

I am creating a power pivot data model on Equipment loan records to clients. Each transaction record has an:
Order Date - when equipment request is submitted on behalf of the client;
Delivery Date - when equipment item is delivered to client;
Collection Date - when equipment item is collected from client.
Each transaction is either a delivery or a collection. The 'Order Type Code' column determines whether a transaction is a delivery or a collection via column entry 'D' or 'C'.
I have created power pivot tables across a range of budgets for deliveries (quantities and value) and collections (quantities and value). Each record has columns for: delivery qty, delivery val, collection qty, collection value, and order value. For a collection the order value is negative.
I have created the DAX measure total formulas for quantities and values for both collections and deliveries, using the 'calculate-SUM function and the appropriate column filters. I have checked the source data to ensure formulas are correct.

When I drop the DAX measures into the pivot table, only the delivery information is correct, and the collection information is not.
In the data model diagram view, the datekey table date is linked to the delivery date as the main link; all the other dates are linked as secondary links. However if I change the datekey date to link with collection date first, and others secondary, the collection information in the pivot table becomes correct, and the delivery information wrong.

What DAX formulas do I use so that both delivery and collection information is correct in the same data model?

RE: Powerpivots

Hi Lloyd,

Thank you for the forum question.

Relate the DateKey to all three dates. You will then get one active relationship and two inactive relationships (you can recognise the inactive relationships be the dash line). Use the Calculate DAX function together with the Userelationship DAX function:

=Calculate("the sum","Your filter",Userelationship(Dates[DateKey],["collection date"]))

The Userelationship function use the inactive relationships. You will need to amend the above example to your table names and field names.

I hope this makes sense otherwise let me know.



Kind regards

Jens Bonde
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
Best STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

RE: Powerpivots

Hi Jens,

I was already aware of the userelationship function, but this does not work in this case. It was used by my predecessor, but the DAX formula is not pulling out the correct figure.

In the userelationship function I had the [date key] and [Collection date] in the opposite order, but changing this around has no effect.

Just to give you some idea what level of info is being picked up.

Standard Collections for one year is 106627. The following DAX formula correctly equates to this figure:

StdColQty:=CALCULATE(SUM([colqty]),FILTER(ClientTransactions,ClientTransactions[serviceType]="STD"),FILTER(ClientTransactions,ClientTransactions[ordtype_code]="C"))

The amended DAX measure as you suggest becomes this, but only pulls a total of 200:

trialStdColQty:=CALCULATE(SUM([colqty]),FILTER(ClientTransactions,ClientTransactions[serviceType]="STD"),FILTER(ClientTransactions,ClientTransactions[ordtype_code]="C"),USERELATIONSHIP(DateKey[FullDate],ClientTransactions[coldate]))

RE: Powerpivots

Hi Lloyd,

I have created a data model to simulate your data model and in my data model it works fine:

userela:=calculate([Total],FILTER(Customers,Customers[Region]="Central"),filter(Items,Items[Unit Price]>100),USERELATIONSHIP(Customers[Contract Date],Dates[DateValue]))

DateValue is my primary key in my dates table.

I do not know why you do not get the right result.

If you send me the workbook, I can have a look at the issue.

Please send it to:

info@stl-training.co.uk

Kind regards

Jens Bonde
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
Best STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

RE: Powerpivots

Hi Lloyd,

I have been looking at your data model.

I can see one problem. You have used the Filter function in your DAX below.

The Filter function shouldn't be used to filter that transaction table.

trialStdColQty:=CALCULATE(SUM([colqty]),ClientTransactions[serviceType]="STD"),FILTER(ClientTransactions,ClientTransactions[ordtype_code]="C",USERELATIONSHIP(DateKey[FullDate],ClientTransactions[coldate]))

The issue is explained if click the link below.

https://powerpivotpro.com/2012/06/filter-when-why-how-to-use-it/

I do not know if this fix all. Please let me know.

Kind regards

Jens Bonde
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
Best STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

RE: Powerpivots

Hi Jens,

I am going to have to take some time to get my head round this one. I am learning that some functions don't work together in the same formula. For now, I don't see a logical reason why the Filter function cannot work with Userelationship; and it certainly doesn't make sense that it worked in a model for you, which is essentially the same as my data model.

Anyway I have found my own solution by splitting the functions. I have applied the Filter function to a DAX calculated column, and combined the Userelationship function to the DAX measure (summation) of the calculated column.

The formula result is correct, and it works perfectly when applied to the pivot table/chart.

RE: Powerpivots

Hi Lloyd,

I am happy, that you got it to work. The DAX logic can give you a headache. The Calculate function can be used for a lot, but can be difficult to get right. You will be able to find a lot of discussions in PowerPivot forums about this function. Many struggle to get it right.
Specially the PowerPivotPro website has many useful tips and tricks for DAX users.


Kind regards

Jens Bonde
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
Best STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

Tue 6 Jun 2017: Automatically marked as resolved.


 

Excel tip:

Quickly Adding New Worksheets

Want to place a new Excel worksheet before current worksheet. Use keystroke SHIFT+F11

View all Excel hints and tips


Server loaded in 0.05 secs.