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
Staregirl
Helper I
Helper I

Measure works with Measure, but not with equivalent Variable?

Hi all

 

I'm confused. I have a set of measures that are the 'blocks' for Event in Progress calculations.

If I try to create a single measure using variables that are, as far as I can see, the same as my measures - I get a different result:

 
 

Capture.PNG

 

LoB means Lines of Business, they have a start and end date.

 

I have:
[PolicyLineCount] - a count of the LoB in my Fact table
[NewActiveLoB] - all active within date filter context
[NewActiveLoBEOP] - all active at the End of Period
[NewAverageLobProd] - average active LoB at End of Period by Producer

 

PolicyLineCount is a measure in our tabular model so I can't see the calculation.

 

NewActiveLoB :=
CALCULATE (
    [Policy Line Count],
    FILTER (
        PolicyLine,
        RELATED ( PolicyLineEffectiveDate[PolicyLineEffectiveDate] )
            <= MAX ( 'Date'[Date] )
            && RELATED ( PolicyLineExpirationDate[PolicyLineExpirationDate] )
                > MIN ( 'Date'[Date] )
    )
)
 
NewActiveLoBEOP :=
CALCULATE(
   [NewActiveLoB],
   FILTER( ALL ('Date'[Date]), 'Date'[Date] =
      MAX('Date'[Date] )
) )
 
NewAverageLoBProd := AVERAGEX(LineServicingProducer, [NewActiveLoBEOP])
 
But this measure does not work - why?:
 
ProducersAverageNoOfLoBEOP :=
VAR NewActiveLoB =
    CALCULATE (
        [Policy Line Count],
        FILTER (
            PolicyLine,
            RELATED ( PolicyLineEffectiveDate[PolicyLineEffectiveDate] ) <= MAX ( 'Date'[Date] )
                && RELATED ( PolicyLineExpirationDate[PolicyLineExpirationDate] ) > MIN ( 'Date'[Date] )
        )
    )
VAR NewActiveLoBEOP =
    CALCULATE (
        NewActiveLoB,
       FILTER ( ALL ( 'Date'[Date] ), 'Date'[Date] = MAX ( 'Date'[Date] ) )
    )
RETURN 

   AVERAGEX (LineServicingProducer, NewActiveLoBEOP)
 
Thanks in advance.

 

1 ACCEPTED SOLUTION

Hi Evelyn

 

They're not tables, they're measures. Someone on another forum has explained it is to do with the calculation context.

 

Since each variable is only calculated once, there is no 'cascade' through the variables in the same way as there is if you chain your measures.

 

So - the first way I did it was the right way. This is not a correct use of Variables.

View solution in original post

3 REPLIES 3
misaki233
Helper II
Helper II

Hi @Staregirl ,

 

It may be caused by the different contexts. According to my experience, I usually split into two or more measures, especially when the return value uses functions such as sumx and averagex.

 

v-eqin-msft
Community Support
Community Support

Hi @Staregirl ,

 

Sorry ,it's a little hard for me to reproduce your issus since there seems to be more than three tables(PolicyLine, PolicyLineExpirationDate, PolicyLineEffectiveDate, Date, LineServicingProducer...)

 

Could you please upload some detailed data samples without unsensitive data?

 

Best Regards,
Eyelyn Qin

 

Hi Evelyn

 

They're not tables, they're measures. Someone on another forum has explained it is to do with the calculation context.

 

Since each variable is only calculated once, there is no 'cascade' through the variables in the same way as there is if you chain your measures.

 

So - the first way I did it was the right way. This is not a correct use of Variables.

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.