Skip to main content
cancel
Showing results for 
Search instead 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.

Reply
Pelle
Frequent Visitor

Create a calculation with two different levels in a dimension table.

Hi.
I need to do a calculation like this.
Avg(value) for level1 DIVIDED Avg(value) for level2.
Her is my data.
dimension table:

Dim.PNG

 

fact table:

Fact.PNG

I have created two different measurs:
Avg Value = AVERAGE('Fact'[Value])
Avg Value without Level1 = CALCULATE(AVERAGE('Fact'[Value]);ALL(Dim[Level1]))
The result in a table:
Table1.PNG

But if I remove the Level2 from the table it ends up dowing it wrong.

Table2.PNG

I understand why but how do I make a measure that is not depended on the visual row context?
Thanks / P

1 ACCEPTED SOLUTION
v-piga-msft
Resident Rockstar
Resident Rockstar

Hi @Pelle,

 

You could try to modify your measure as below.

 

Avg Value without Level1 =
CALCULATE (
    AVERAGE ( 'fact'[Value] ),
    FILTER ( ALL ( dim ), 'dim'[Level2] = MAX ( 'dim'[Level2] ) )
)

And the result will be your expected output.

 

Capture.PNG

Hope it can help you!

 

Best Regards,

Cherry

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-piga-msft
Resident Rockstar
Resident Rockstar

Hi @Pelle,

 

You could try to modify your measure as below.

 

Avg Value without Level1 =
CALCULATE (
    AVERAGE ( 'fact'[Value] ),
    FILTER ( ALL ( dim ), 'dim'[Level2] = MAX ( 'dim'[Level2] ) )
)

And the result will be your expected output.

 

Capture.PNG

Hope it can help you!

 

Best Regards,

Cherry

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

This solution works great in powerbi dax but I'm using SSAS tabulare 2016 in DirectQuery mode.
The Max() function only works with numbers or dates (except when used in inmemory 🙂 ).

So I'm stuck with my old code but it turned out alright as long as I have Level2 attributes with me in my visuals.

Or is there another work around?

/P

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

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

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors