cancel
Showing results for
Did you mean:

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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 :

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(
"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,

1 ACCEPTED SOLUTION
Super User

Hi,

You may download my PBI file from here.

Hope this helps.

Regards,
Ashish Mathur
http://www.ashishmathur.com
3 REPLIES 3
Super User

Hi,

You may download my PBI file from here.

Hope this helps.

Regards,
Ashish Mathur
http://www.ashishmathur.com
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.

Super User

You are welcome.

Regards,
Ashish Mathur
http://www.ashishmathur.com

Announcements

#### Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

#### Power BI Monthly Update - April 2024

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

#### Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors