Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
I'm attempting to understand why a measure I've written doesn't work and see if there's something I can do to fix it.
Overview of Data & Measures
I'm dealing with shipping data and have a Table visual which has an Origin, Destination, and various numeric measures.
The numeric measures, at their base, are just SUMs of a field in the data, but also do some other tricks:
Requirement
I am attempting to create Card visuals which displays the SUM of the top 5 rows of this table for the measures described above.
My Attempt
As an example, I am using the following measure
Top 5 =
SUMX(
TOPN(
5,
SUMMARIZE(
'Shipments',
'Shipments'[Origin],
'Shipments'[Destination],
"Total Paid", [Total Paid (USD) Sum]),
[Total Paid], DESC),
[Total Paid])
Here's the other measure it's referencing:
Total Amount Paid (USD) Sum =
VAR DateSelection = SELECTEDVALUE('Date Slicer Choices'[Date Choice])
VAR TotalPaidInvoiceDate =
CALCULATE(
SUM('Shipments'[TOTAL_PAID_USD]),
USERELATIONSHIP('Date'[DATE], 'Shipments'[INVOICE_DATE]))
VAR TotalPaidProcessedDate =
CALCULATE(
SUM('Shipments'[TOTAL_PAID_USD]),
USERELATIONSHIP('Date'[DATE], ' Shipments'[PROCESSED_DATE]))
VAR TotalPaidShipDate =
CALCULATE(
SUM('Shipments'[TOTAL_PAID_USD]),
USERELATIONSHIP('Date'[DATE], 'Shipments'[SHIP_DATE]))
RETURN
SWITCH(
TRUE(),
DateSelection = "Invoice Date", TotalPaidInvoiceDate,
DateSelection = "Ship Date", TotalPaidShipDate,
DateSelection = "Processed Date", TotalPaidProcessedDate)
This measure allows the user to control which of the three date choices. The measure behaves as expected when used in a visual such as the Table visual.
In the data model the Date table has three relationships to the Shipment table. The Date[DATE] is joined to Shipment[INVOICE_DATE], Shipment[SHIP_DATE] (the active join), and Shipment[PROCESSED_DATE].
My Issue
The Top 5 measure works beautifully when the Date selection is the one that is the active relationship between the Date Table and the Shipment table.
When I select either of the other Date types which are using the inactive relationships, it returns (Blank). I'm quite confused as to why as the subordinate measures (the ones that calculate the Total Paid doing the date SWITCH), both work as expected in the Table visual.
Thus, there seems to be some sort of issue passing this second measure into the the first that I'm not understanding.
Solved! Go to Solution.
Hi @VoijaRisa
Based on your detailed description, I have added some steps to the actions you have already taken, and in my simple tests it is working. I hope the following steps will be helpful to you.
Here's my data model:
1. Create the "Total Amount Paid (USD) Sum" measure in the same way as you used it.
2. Create separate measures to calculate Top5 for different date selections.
Top 5 Ship Date =
SUMX(
TOPN(
5,
ADDCOLUMNS(
SUMMARIZE(
'Shipments',
'Shipments'[Origin],
'Shipments'[Destination]
),
"Total Paid USD", [Total Amount Paid (USD) Sum]
),
[Total Paid USD], DESC
),
[Total Paid USD]
)
Top 5 Invoice Date =
CALCULATE(
SUMX(
TOPN(
5,
ADDCOLUMNS(
SUMMARIZE(
'Shipments',
'Shipments'[Origin],
'Shipments'[Destination]
),
"Total Paid USD", [Total Amount Paid (USD) Sum]
),
[Total Paid USD], DESC
),
[Total Paid USD]
),
USERELATIONSHIP('Date'[DATE], 'Shipments'[INVOICE_DATE])
)
Top 5 Processed Date =
CALCULATE(
SUMX(
TOPN(
5,
ADDCOLUMNS(
SUMMARIZE(
'Shipments',
'Shipments'[Origin],
'Shipments'[Destination]
),
"Total Paid USD", [Total Amount Paid (USD) Sum]
),
[Total Paid USD], DESC
),
[Total Paid USD]
),
USERELATIONSHIP('Date'[DATE], 'Shipments'[PROCESSED_DATE])
)
3. Combine the Top5 measures created above into one measure.
Top 5 =
VAR DateSelection = SELECTEDVALUE('Date Slicer Choices'[Date Choice])
RETURN
SWITCH(
TRUE(),
DateSelection = "Invoice Date", [Top 5 Invoice Date],
DateSelection = "Processed Date", [Top 5 Processed Date],
DateSelection = "Ship Date", [Top 5 Ship Date]
)
4. Create a card visual with Top 5 measure.
5. Here is final result:
Best Regards,
Jarvis Tang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @VoijaRisa
Based on your detailed description, I have added some steps to the actions you have already taken, and in my simple tests it is working. I hope the following steps will be helpful to you.
Here's my data model:
1. Create the "Total Amount Paid (USD) Sum" measure in the same way as you used it.
2. Create separate measures to calculate Top5 for different date selections.
Top 5 Ship Date =
SUMX(
TOPN(
5,
ADDCOLUMNS(
SUMMARIZE(
'Shipments',
'Shipments'[Origin],
'Shipments'[Destination]
),
"Total Paid USD", [Total Amount Paid (USD) Sum]
),
[Total Paid USD], DESC
),
[Total Paid USD]
)
Top 5 Invoice Date =
CALCULATE(
SUMX(
TOPN(
5,
ADDCOLUMNS(
SUMMARIZE(
'Shipments',
'Shipments'[Origin],
'Shipments'[Destination]
),
"Total Paid USD", [Total Amount Paid (USD) Sum]
),
[Total Paid USD], DESC
),
[Total Paid USD]
),
USERELATIONSHIP('Date'[DATE], 'Shipments'[INVOICE_DATE])
)
Top 5 Processed Date =
CALCULATE(
SUMX(
TOPN(
5,
ADDCOLUMNS(
SUMMARIZE(
'Shipments',
'Shipments'[Origin],
'Shipments'[Destination]
),
"Total Paid USD", [Total Amount Paid (USD) Sum]
),
[Total Paid USD], DESC
),
[Total Paid USD]
),
USERELATIONSHIP('Date'[DATE], 'Shipments'[PROCESSED_DATE])
)
3. Combine the Top5 measures created above into one measure.
Top 5 =
VAR DateSelection = SELECTEDVALUE('Date Slicer Choices'[Date Choice])
RETURN
SWITCH(
TRUE(),
DateSelection = "Invoice Date", [Top 5 Invoice Date],
DateSelection = "Processed Date", [Top 5 Processed Date],
DateSelection = "Ship Date", [Top 5 Ship Date]
)
4. Create a card visual with Top 5 measure.
5. Here is final result:
Best Regards,
Jarvis Tang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi,
I am not sure of how much i can help but i would like to try. Share the download link of the PBI file.
Check out the July 2025 Power BI update to learn about new features.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
User | Count |
---|---|
70 | |
68 | |
43 | |
34 | |
26 |
User | Count |
---|---|
86 | |
49 | |
45 | |
38 | |
37 |