Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
admin_xlsior
Post Prodigy
Post Prodigy

Put 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 :
image.png
 
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 :
image.png
 
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,
 
1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

3 REPLIES 3
Ashish_Mathur
Super User
Super User

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

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. Smiley Very Happy

 

 

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

Check out the September 2024 Power BI update to learn about new features.

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

Find out what's new and trending in the Fabric Community.