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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

DAX: Group results from Measure by Day and Hour

The following formula shows the difference between 1 row and the last. I spent a long time working on this and needed the help of someone here to get it to this point. But the result is showing the difference PER ENTRY, while I am looking for PER DAY and PER HOUR. 

 

BPS = 
VAR _currentlastvalue =
    CALCULATE ( SUM ( 'Table'[Value]), 'Table'[Date] = MAX ( 'Table'[Date] ) )
VAR _prevlasttime =
    MAXX (
        FILTER (
            ALL ( 'Table' ),
            'Table'[Item] = MAX ( 'Table'[Item])
                && 'Table'[Date] < MAX ( 'Table'[Date] )
        ),
        'Table'[Date]
    )
VAR _prevlastvalue =
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER (
            ALL ( 'Table'),
            'Table'[Item] = MAX ( 'Table'[Item] )
                && 'Table'[Date] < MAX ( 'Table'[Date] )
                && 'Table'[Date] = _prevlasttime
        )
    )
RETURN
        IF (
        ISINSCOPE ( 'Table'[Date] ) && ISINSCOPE ( 'Table'[Item] ),
        SWITCH (
            TRUE (),
            _prevlastvalue <> BLANK (), _currentlastvalue - _prevlastvalue,
            _prevlastvalue = BLANK (), 0
        )
    )

 

 

So I believe a Summarize function is needed to group this measure into days and hours. Perhaps I'll need 2 separate measures, which is fine.

 

Thank you!

1 REPLY 1
v-jianboli-msft
Community Support
Community Support

Hi @Anonymous ,

 

What does your raw data look like?

Sorry for that the information you have provided is not making the problem clear to me. Can you please share more details to help us clarify your scenario?

Please provide me with more details about your table and your problem or share me with your pbix file after removing sensitive data.

 

Refer to:

How to provide sample data in the Power BI Forum

How to Get Your Question Answered Quickly

 

Best Regards,

Jianbo Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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