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
ITManuel
Responsive Resident
Responsive Resident

Issue with time intelligence using variables

Hi all,

 

I have the following measure calculating project progress. 

RPnew = 
VAR StatusDate = [StatusDate]
VAR Result =
    CALCULATE (
        SUMX (
            FILTER ( RP, RP[Group] = "Design" ),
            RP[Progress] * RELATED ( IW[Weighting] )
                * RELATED ( GW[Weighting] )
        )
            + SUMX (
                FILTER ( RP, RP[Group] = "Purchasing" ),
                RP[Progress] * RELATED ( IW[Weighting] )
                    * RELATED ( GW[Weighting] )
            )
            + SUMX (
                FILTER ( RP, RP[Group] = "Construction" ),
                RP[Progress] * RELATED ( IW[Weighting] )
                    * RELATED ( GW[Weighting] )
            )
            + SUMX (
                FILTER ( RP, RP[Group] = "Commissioning" ),
                RP[Progress] * RELATED ( IW[Weighting] )
                    * RELATED ( GW[Weighting] )
            ),
        RP[Date] <= EOMONTH ( StatusDate, 0 )
    )
RETURN
    Result

I have progress data beyond the Status date (which is 31.08.2021) in this case, this is why I have to limit the calculation within the Status date which is working. This is the result:

 

V1.JPG

 

 

 

 

 

 

 

 

 

Even though progress data is available also after 31.08.2021 it show only data within that date. 

 

To make the code more readable I wanted to use variables.

RPnew = 
VAR StatusDate = [StatusDate]
VAR DRP =
    SUMX (
        FILTER ( RP, RP[Group] = "Design" ),
        RP[Progress] * RELATED ( IW[Weighting] )
            * RELATED ( GW[Weighting] )
    )
VAR PRP =
    SUMX (
        FILTER ( RP, RP[Group] = "Purchasing" ),
        RP[Progress] * RELATED ( IW[Weighting] )
            * RELATED ( GW[Weighting] )
    )
VAR CRP =
    SUMX (
        FILTER ( RP, RP[Group] = "Construction" ),
        RP[Progress] * RELATED ( IW[Weighting] )
            * RELATED ( GW[Weighting] )
    )
VAR COMRP =
    SUMX (
        FILTER ( RP, RP[Group] = "Commissioning" ),
        RP[Progress] * RELATED ( IW[Weighting] )
            * RELATED ( GW[Weighting] )
    )
VAR RealProgress = DRP + PRP + CRP + COMRP
VAR Result =
    CALCULATE ( RealProgress, RP[Date] <= EOMONTH ( StatusDate, 0 ) )
RETURN
    Result

However with this code the calculation is not anymore limited to the Status date which is 31.08.2021 and I don't understand why.

 

V2.JPG

 

 

 

 

 

 

 

 

 

Thanks in advance

 

Br

3 REPLIES 3
lbendlin
Super User
Super User

Any particular reason for using RELATED() in a measure?

 

You can also simplify your filter quite a bit

 

FILTER ( RP, RP[Group] IN {"Design","Purchasing","Construction","Commissioning"} )
ITManuel
Responsive Resident
Responsive Resident

Hi @lbendlin

 

this is my data model 

DataModel.JPG

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

DataModel1.png

The table IW and GW are on the one side of the relationship to RP this is why I'm using RELATED() to access the Weighting values in IW and GW.

ITManuel
Responsive Resident
Responsive Resident

Hi,

 

any suggestions as to why the same formula works without but does not work using variables?

 

Br

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.