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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Osama14
Frequent Visitor

Calculating Consumption from day before

Hi, 

I have a data set gathering readings from various meters per mintue in a table called historian, the readings are accumlated, i am trying to get the daily consumption by getting the difference of start of day 2 and Day 1, which should be:  "03-07-21 00:00:00 - 02-07-21 00:00:00" 

 

I have used the below formula by getting the minimum of the day.  

  

Meter 1 Consumption = 
IF(
    ISFILTERED('Historian'[Date]),
    ERROR("Time intelligence quick measures can only be grouped or filtered by the Power BI-provided date hierarchy or primary date column."),
    VAR __PREV_Day =
        CALCULATE(
            MIN('Historian'[QC Meter 1]),
            DATEADD('Historian'[Date].[Date], -1, DAY)
        )
    RETURN
MIN('Historian'[QC Meter 1]) - __PREV_DAY)

 

I am having 2 problems, 

 

1-  a total value showing for previous day in 1st row  - Note that the days in data starts on the 2nd of july and no data for 1st.  

Osama14_1-1631008065390.png

 

2- The Meter sometimes reset when it reaches 9,999,999 as below , so taking the value minimum value of that day will not work.

 

Osama14_2-1631009153177.png

 

What will be the best way to deal with this and get the accurate daily consumption even if meter resets.

any advice is much appreciated. 

1 ACCEPTED SOLUTION
Osama14
Frequent Visitor

I have managed to find a work around whenever the meter gets reset, by having an If condition and adding the maximum reading number to the last value and subtracting the next day reading. 

 

Thanks 

View solution in original post

5 REPLIES 5
Osama14
Frequent Visitor

I have managed to find a work around whenever the meter gets reset, by having an If condition and adding the maximum reading number to the last value and subtracting the next day reading. 

 

Thanks 

Anonymous
Not applicable

Hi @Osama14,

Thanks for your sharing.😊

I think this workaround will be helpful if others faced a similar scenario.

Regards,

Xiaoxin Sheng

Anonymous
Not applicable

Hi @Osama14,

Can you please share a pbix or some dummy data that keep raw data structure with expected results? It should help us clarify your scenario and test to coding formula.

How to Get Your Question Answered Quickly  

Regards,

Xiaoxin Sheng

CNENFRNL
Community Champion
Community Champion

Use the following pattern to extract the latest reading in a day,

Latest Reading =
MAXX( TOPN( 1, Historian, Historian[DateTime] ), Historian[Reading] )

Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Hi, Thank you for your response 

 

but your formula will get the latest reading or max per the day which accumlated from the day before, i need to have the difference between day 2 and day 1.  I need only the consumption happened on the day. 

 

Thanks 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.