Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
MarcW
Frequent Visitor

Userrelationship / ParrallelPeriod wrong subtotals

Hi all,

 

I have a problem with wrong subtotals in my calculations using Userrelationship / ParrallelPeriod.

The fact table contains cost information per employee and two date columns, date and source date (= snapshot date of data extraction).

 

Situation:

 

Ex1.JPGFor my Solution I use this measure

 

MaxSourcedate =

VAR CY = 0    

VAR Source =
    CALCULATE(
         MAX( WorkDay[SourceDate] ),  
            USERELATIONSHIP( WorkDay[SourceDate], 'Date'[Date] ) ,
            PARALLELPERIOD('Date'[Date], CY, YEAR)    
        )                                              


VAR Result =
    CALCULATE(
        [Annual Pay],
        FILTER(
            ALL(WorkDay[SourceDate]),
                WorkDay[SourceDate] = Source
    )
)

RETURN

Result

 

For the PY:

 

MaxSourcedate PY =

VAR PY = -1    

VAR SourcePY =
    CALCULATE(
         MAX( WorkDay[SourceDate] ),  
            USERELATIONSHIP( WorkDay[SourceDate], 'Date'[Date] ) ,
            PARALLELPERIOD('Date'[Date], PY, YEAR)
        )


VAR Result =
    CALCULATE(
        [Annual Pay],
        DATEADD('Date'[Date], PY, YEAR),
        FILTER(
            ALL(WorkDay[SourceDate]),
                WorkDay[SourceDate] = SourcePY
    )
)

RETURN

Result

 

Problem:

 

Ex2.JPG

 

I am not sure what I do wrong. My best guess is that my filter argument with

FILTER(
            ALL(WorkDay[SourceDate]),
                WorkDay[SourceDate] = SourcePY
gives back all values of the last sourcedate but then is not summing up in the totals. Has anyone an idea to fix that? Thanks in advance. 🙂

 

 

 

 

 

1 ACCEPTED SOLUTION

Thanks for getting back to me. Unfortunately that was not working for me. In the meantime I did get help in another forum. My code missed a REMOVEFILTERS condition. Then it works fine:

 

MaxSourcedate =

VAR CY = 0

VAR Source =
CALCULATE(
     MAX( WorkDay[SourceDate] ),
     USERELATIONSHIP( WorkDay[SourceDate], 'Date'[Date] ) ,
     PARALLELPERIOD('Date'[Date], CY, YEAR) ,

     REMOVEFILTERS ( 'WorkDay' )
)


VAR Result =
CALCULATE(
     [Annual Pay],
          FILTER(
          ALL(WorkDay[SourceDate]),
          WorkDay[SourceDate] = Source
     )
)

RETURN

Result

 

 

Thanks a lot anyway.

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@MarcW , Try like

 

Var _measure = CALCULATE(
[Annual Pay] ,USERELATIONSHIP( WorkDay[SourceDate], 'Date'[Date] ) )

VAR Result =
CALCULATE(
_measure,
Dateadd('Date'[Date], -1, year)
)

 

 

Have measure with userelationship and then use time intelligence

 

Check the last period formula in my Hr file, attached after signature 

Thanks for getting back to me. Unfortunately that was not working for me. In the meantime I did get help in another forum. My code missed a REMOVEFILTERS condition. Then it works fine:

 

MaxSourcedate =

VAR CY = 0

VAR Source =
CALCULATE(
     MAX( WorkDay[SourceDate] ),
     USERELATIONSHIP( WorkDay[SourceDate], 'Date'[Date] ) ,
     PARALLELPERIOD('Date'[Date], CY, YEAR) ,

     REMOVEFILTERS ( 'WorkDay' )
)


VAR Result =
CALCULATE(
     [Annual Pay],
          FILTER(
          ALL(WorkDay[SourceDate]),
          WorkDay[SourceDate] = Source
     )
)

RETURN

Result

 

 

Thanks a lot anyway.

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Top Solution Authors