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
faustusxanthis
Frequent Visitor

DAX Measure to calculate all unique/max entries but from previous week

Hello! 

 

I have tried searching here but I can't seem to find the right DAX expression/measure for this. 

 

I have this data: 

EMPLOYEE IDPAY PERIODThis week's payHourly Rate
15/26/2024$400$10
25/26/2024$349$9
35/26/2024$271$11
45/26/2024$523$7
35/26/2024$306$11
25/19/2024$503$9
15/19/2024$213$10
45/19/2024$321$7
15/19/2024$100$10

 

I want to make a measure wherein it will calculate the sum of all hourly rate per unique employee but should calculate the previous week's data. 

For example, in the PowerBI filter, I selected 5/26/2024. I should get the sum of all the hourly rate (1 employee = 1 hourly rate or it could be the MAX of the hourly rate per employee ID) for the previous week (5/19/2024). In this case, if I select 5/26/2024, it should calculate the sum of hourly rate of empoyee 1, 2, and 4 only since they are the only available data from the previous week ($10 + $9 + $7) which is $26
If I select 5/19/2024, it should display $0 since there's no data for the previous week. 

 

I already tried the below code but it always shows a blank value 😞 I assume it's because the data only shows all the entries of the pay period in whatever pay period is selected in the filter. 

 

 

 

 

 

VAR Prev_Week = MAX('Example_Table'[DateColumn]) - 7
RETURN
    SUMX(
        SUMMARIZE(
            FILTER(
                'Example_Table',
                'Example_Table'[Pay Period] = Prev_Week
            ),
            'Example_Table'[Employee ID],
            "Total Hourly Rate", MAX('Example_Table'[Hourly Rate])
        ),
        [Total Hourly Rate]
    )

 

 

 

 

 

 

1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@faustusxanthis try this:

 

VAR Prev_Week = MAX('Example_Table'[DateColumn]) - 7
RETURN
    SUMX(
        SUMMARIZE(
            FILTER(
                ALL ( 'Example_Table'[Pay Period], 'Example_Table'[Employee ID] ),
                'Example_Table'[Pay Period] = Prev_Week
            ),
            'Example_Table'[Employee ID],
            "Total Hourly Rate", MAX('Example_Table'[Hourly Rate])
        ),
        [Total Hourly Rate]
    )


Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

3 REPLIES 3
v-huijiey-msft
Community Support
Community Support

Hi @faustusxanthis ,

 

Your solution is great, @Ashish_Mathur / @parry2k . It worked like a charm! Here I have another idea in mind, and I would like to share it for reference.

 

Please try:

 

Create a measure:

PreviousWeekHourlyRateSum = 
VAR SelectedWeekStart = MIN('Example_Table'[Pay Period])
VAR PreviousWeekStart = SelectedWeekStart - 7
VAR PreviousWeekEnd = SelectedWeekStart - 1
VAR PreviousWeekData = 
    CALCULATETABLE(
        SUMMARIZE(
            'Example_Table',
            'Example_Table'[Employee ID],
            "MaxHourlyRate", MAX('Example_Table'[Hourly Rate])
        ),
        'Example_Table'[Pay Period] >= PreviousWeekStart,
        'Example_Table'[Pay Period] <= PreviousWeekEnd
    )
RETURN
    SUMX(
        PreviousWeekData,
        [MaxHourlyRate]
    )

 

The page effect is as shown below:

vhuijieymsft_0-1716779705557.png

 

pbix file is attached.

 

If you have any further questions please feel free to contact me.

 

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

Ashish_Mathur
Super User
Super User

Hi,

PBI file attached.

Hope this helps.

Ashish_Mathur_0-1716693227448.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
parry2k
Super User
Super User

@faustusxanthis try this:

 

VAR Prev_Week = MAX('Example_Table'[DateColumn]) - 7
RETURN
    SUMX(
        SUMMARIZE(
            FILTER(
                ALL ( 'Example_Table'[Pay Period], 'Example_Table'[Employee ID] ),
                'Example_Table'[Pay Period] = Prev_Week
            ),
            'Example_Table'[Employee ID],
            "Total Hourly Rate", MAX('Example_Table'[Hourly Rate])
        ),
        [Total Hourly Rate]
    )


Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

July 2024 Power BI Update

Power BI Monthly Update - July 2024

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

July Newsletter

Fabric Community Update - July 2024

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