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
KBL1974
Regular Visitor

How can I make a dynamic Measure behave like a hard coded number ?

Hi All,
Im trying to solve a DAX dilemma. I relates to the way a measure is handled by another measure.
I'll try to explain clearly.

------------------------------------------------------------------------------------------------------------------------------------------

[Measure1] calculates the maximum days in the current week where we have data.

Measure1:=CALCULATE (
MAX ( 'Activations'[DayOrder] ),
FILTER ( 'Date', 'Date'[Relative Week] = "Current Week" ),
FILTER ( 'Activations', [Units] > 0 )
)

The result is 4
------------------------------------------------------------------------------------------------------------------------------------------

[Measure2] now calculates the equivalent days from the previous week, using the calculation result from [Measure1] 4.

Measure2:=CALCULATE (
[Units],
FILTER ( 'Date', 'Date'[Relative Week] = "Current Week -1" ),
FILTER (
'Activations',
[DayOrder]
<= CALCULATE (
MAX ( 'Activations'[DayOrder] ),
FILTER ( 'Date', 'Date'[Relative Week] = "Current Week" ),
FILTER ( 'Activations', [Units] > 0 )
)
)
)

The result is 123,456.

------------------------------------------------------------------------------------------------------------------------------------------
Issue:

When creating a pivot table using [Date] on rows and [Measure2] on columns we only get a sum total value.

We cannot drill down any further
example a.PNG
I need to be able to have the [Date] granularity
example b.PNG


------------------------------------------------------------------------------------------------------------------------------------------

 

[Measure3] is the same as [Measure2] except it uses the hard coded value 4 instead of the calculation result from [Measure1] ) also 4).

Measure3:=CALCULATE (
[Units],
FILTER ( 'Date', 'Date'[Relative Week] = "Current Week -1" ),
FILTER (
'Activations',
[DayOrder]
<= 4
)
)

The result is also 123,456 but this time the [Date] granularity is available.
example b.PNG

------------------------------------------------------------------------------------------------------------------------------------------


So the question is :    How can I make the dynamic [Measure1], (which calculates to 4), act like a hardcoded number 4

Thank you in advance.

1 REPLY 1
v-shex-msft
Community Support
Community Support

HI @KBL1974,

 

For your scenario, it seems like the filter not correct works on your nested measures, can please share the sample pbix file to test?

Did you try to use var function to store the measure result, the use it as the condition in filter?

Measure2 :=
VAR temp =
    CALCULATE (
        MAX ( 'Activations'[DayOrder] ),
        FILTER ( 'Date', 'Date'[Relative Week] = "Current Week" ),
        FILTER ( 'Activations', [Units] > 0 )
    )
RETURN
    CALCULATE (
        [Units],
        FILTER ( 'Date', 'Date'[Relative Week] = "Current Week -1" ),
        FILTER ( 'Activations', [DayOrder] <= temp )
    )

BTW, I think [Units] is also a measure, right?

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

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.