Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started
Hi,
I have Dim_Customer table with the following:
PK_Cust_ID Cust_Name
111 TKL Supplies
112 TKL Supplies
113 TKL Supplies
289 OCCAs
29900 OCCAs
The Dim_Customer.PK_Cust_ID column joins to the Fact.FK_Cust_ID table. The Fact table looks like this:
FK_Cust_ID Date Sales Depot
111 01/02/2019 122.00 22
111 20/03/2019 8.00 22
112 01/01/2019 28.00 22
111 23/05/2019 61.00 28
289 20/05/2019 88.00 22
113 20/02/2019 112.00 89
I should say there is no slicer placed on the Cust_Name in the report. The only context filtering used is the Cust_Name column within a Matrix visiual.
What I need to be able to calcuate is the latest (last) date for the Cust_Name regardless of what Cust_IDs the Cust_Name may have, or the Depots the transaction is recorded against.
For example, in the Matrix visual, for the row where the Cust_Name is TKL Supplies I need the measure to return the 23/05/2019 as this is the latest date present for the TKL Supplies customer, regardless of the customer's Cust_ID or Depot.
How do I write this measure?
Of course, the measure will need to work out the same for every customer (Cust_Name) so the measure will need to take into account the Matrix visual's context filtering.
Thanks.
Solved! Go to Solution.
I guess that there is a one-way relationship between your DIM and your FACT. So when you put your fact in your matrix, the DIM is not filtered against, therefore there is no Filter context applied.
The weird aspect is that you have several Customer IDs for the same Customer Name...
First of all, for simplicity I would add the Cust_name in the fact with a custom column
Cust_Name=RELATED(Dim_Customer[Cust_Name])
Then another custom column (or a measure if the other filters changes context...)
LastDate=
VAR thisCustName=SELECTEDVALUE(Fact[CustName])
RETURN
MAXX(FILTER(Dim_Customer;Dim_Customer[Cust_Name]=thisCustName);Dim_Customer[Date])
The MAXX iterates along all of the filtered rows and choose the max value.
Should work
I guess that there is a one-way relationship between your DIM and your FACT. So when you put your fact in your matrix, the DIM is not filtered against, therefore there is no Filter context applied.
The weird aspect is that you have several Customer IDs for the same Customer Name...
First of all, for simplicity I would add the Cust_name in the fact with a custom column
Cust_Name=RELATED(Dim_Customer[Cust_Name])
Then another custom column (or a measure if the other filters changes context...)
LastDate=
VAR thisCustName=SELECTEDVALUE(Fact[CustName])
RETURN
MAXX(FILTER(Dim_Customer;Dim_Customer[Cust_Name]=thisCustName);Dim_Customer[Date])
The MAXX iterates along all of the filtered rows and choose the max value.
Should work
@Anonymous
Thanks for your response. I shall attempt to implement it now.
This is what I have tried in the mean time, without joy. Can you see what I'm thinking in my attempt and could it work with the right tweaks (what are they)?
(the table/field names have changed slightly from my initial post)
A calculateTable *inside* a Calculate with a Few ALL() around...you like headaches, don't you? 🙂
That means two context transitions plus a couple of ALL that modify filters...
First of all the CALCULATETABLE is needed when you have relationships, but on the one-side. What you want to do (i guess) with this piece:
CALCULATETABLE( Dim_Customer , ALL( Dim_Customer ) , Dim_Customer[K8 Customer Name] = __Customer )
@Anonymous
Thanks again. Your solution worked. I just needed to added an ALL() clause on the Depot and all was perfect.
Still interested to know if my attempted (code snippet) in the previous post was close to working and could it work with some minor tweaks?
Check out the September 2024 Power BI update to learn about new features.
Learn from experts, get hands-on experience, and win awesome prizes.
User | Count |
---|---|
103 | |
98 | |
98 | |
38 | |
37 |
User | Count |
---|---|
152 | |
120 | |
73 | |
72 | |
63 |