Forum Discussion
admin_xlsior
Post Prodigy
6 years agoPut a measure in Matrix
Hello everyone,
I'm creating an aging report based on user selection of date, and recently I've been confused on the logic of how to put a measure correctly in a matrix.
I've attached a link to my sample for easier explanation :
So, in that PBIX there is a Matrix visualization which is my final result :
The main idea is:
1. I have a measures that calculate aging of my transaction table (measure name = [AgingWithTotal]
2. I have a setup table for the aging bucket with the min and max value named Range
I've created a measure for determine the range like below:
Aging range =
VAR VirtualTable = CALCULATETABLE(
ADDCOLUMNS(FactInternetSales,
"TmpAging", [Aging with Total]
),
ALLSELECTED(DimDate[FullDateAlternateKey])
)
RETURN CALCULATE([Total sales amount],
FILTER(VirtualTable,
COUNTROWS(
FILTER(Range,
[TmpAging] >= Range[Min] &&
[TmpAging] <= Range[Max]
)
) > 0
)
)If using Table Visualization, that measure already looks correct :
But using Matrix, the column is wrong (like the 1st picture, "Final Result"), it only goes to the leftmost column.
I've been reading one good example which explain this behaviour as well in SQLBI.com :
Marco talking about the need of using "ALLSELECTED" otherwise will have the same result as mine right now. Actually, I've tried that as well, I changed my code to be like this :
Aging range 2 =
VAR VirtualTable = ADDCOLUMNS(FactInternetSales,
"TmpAging",
CALCULATE(
[Aging with Total],
CALCULATETABLE(FactInternetSales,
ALLSELECTED(DimDate[FullDateAlternateKey])
)
)
)
RETURN CALCULATE([Total sales amount],
FILTER(VirtualTable,
COUNTROWS(
FILTER(Range,
[TmpAging] >= Range[Min] &&
[TmpAging] <= Range[Max]
)
) > 0
)
)but it seems not working.Does anyone know where I should correct that measure ?
Many thanks in advance,
3 Replies
- Ashish_Mathur
Super User
- admin_xlsior
Post Prodigy
Hi Ashish,
It's great.
In your code ->
ADDCOLUMNS( VALUES(FactInternetSales[SalesOrderNumber]), "ABCD", CALCULATE ( [Aging], CALCULATETABLE ( VALUES(FactInternetSales[SalesOrderNumber]) ), ALLSELECTED() ) ),I'm not sure why we need to specify Saler Order Number or in other word, it needs only one column "Sales Order Number" in that "virtual table". However it is works!!
Thank you very much for your help.
GBU. :smileyvery-happy:
- Ashish_Mathur
Super User
You are welcome.