Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
Hi all,
I have the electric reading data as below. I am looking to calculate the consumption of electric every month based on level. the logic is [ reading current month - reading previous month = current month consumption].
My question is how can i create the dax based on data I have as below;
thanks in advance for help!
Solved! Go to Solution.
Hi @Anonymous ,
I created a sample pbix file(see attachment) for you, please check whether that is what you want. You can create a calculated column or measure as below:
calculated column:
Column =
VAR _year =
IF ( 'Table'[Month] = 1, 'Table'[Year] - 1, 'Table'[Year] )
VAR _month =
IF ( 'Table'[Month] = 1, 12, 'Table'[Month] - 1 )
VAR _premreading =
CALCULATE (
SUM ( 'Table'[reading] ),
FILTER (
ALLSELECTED ( 'Table' ),
'Table'[Level] = EARLIER('Table'[Level])
&& 'Table'[Year] = _year
&& 'Table'[Month] = _month
)
)
RETURN
IF(ISBLANK(_premreading),BLANK(),'Table'[reading]-_premreading)
Measure:
consumption =
VAR _curlevel =
SELECTEDVALUE ( 'Table'[Level] )
VAR _curyear =
SELECTEDVALUE ( 'Table'[Year] )
VAR _curmonth =
SELECTEDVALUE ( 'Table'[Month] )
VAR _year =
IF ( _curmonth = 1, _curyear - 1, _curyear )
VAR _month =
IF ( _curmonth = 1, 12, _curmonth - 1 )
VAR _premreading =
CALCULATE (
SUM ( 'Table'[reading] ),
FILTER (
ALLSELECTED ( 'Table' ),
'Table'[Level] = _curlevel
&& 'Table'[Year] = _year
&& 'Table'[Month] = _month
)
)
RETURN
IF(ISBLANK(_premreading),BLANK(),SUM('Table'[reading])-_premreading)
If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.
How to upload PBI in Community
Best Regards
Hi @Anonymous ,
I created a sample pbix file(see attachment) for you, please check whether that is what you want. You can create a calculated column or measure as below:
calculated column:
Column =
VAR _year =
IF ( 'Table'[Month] = 1, 'Table'[Year] - 1, 'Table'[Year] )
VAR _month =
IF ( 'Table'[Month] = 1, 12, 'Table'[Month] - 1 )
VAR _premreading =
CALCULATE (
SUM ( 'Table'[reading] ),
FILTER (
ALLSELECTED ( 'Table' ),
'Table'[Level] = EARLIER('Table'[Level])
&& 'Table'[Year] = _year
&& 'Table'[Month] = _month
)
)
RETURN
IF(ISBLANK(_premreading),BLANK(),'Table'[reading]-_premreading)
Measure:
consumption =
VAR _curlevel =
SELECTEDVALUE ( 'Table'[Level] )
VAR _curyear =
SELECTEDVALUE ( 'Table'[Year] )
VAR _curmonth =
SELECTEDVALUE ( 'Table'[Month] )
VAR _year =
IF ( _curmonth = 1, _curyear - 1, _curyear )
VAR _month =
IF ( _curmonth = 1, 12, _curmonth - 1 )
VAR _premreading =
CALCULATE (
SUM ( 'Table'[reading] ),
FILTER (
ALLSELECTED ( 'Table' ),
'Table'[Level] = _curlevel
&& 'Table'[Year] = _year
&& 'Table'[Month] = _month
)
)
RETURN
IF(ISBLANK(_premreading),BLANK(),SUM('Table'[reading])-_premreading)
If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.
How to upload PBI in Community
Best Regards
Hi,
Create a Index in power Query, then create below Column in particular table :
@Anonymous , Create a date with help from month and year, and join it with date of date table and use TI for meaures
Date = date([year], [month],1)
MTD Sales = CALCULATE(SUM(Table[reading]),DATESMTD('Date'[Date]))
last MTD Sales = CALCULATE(SUM(Table[reading]),DATESMTD(dateadd('Date'[Date],-1,MONTH)))
last month Sales = CALCULATE(SUM(Table[reading]),previousmonth('Date'[Date]))
Power BI — Month on Month with or Without Time Intelligence
https://medium.com/@amitchandak.1978/power-bi-mtd-questions-time-intelligence-3-5-64b0b4a4090e
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
72 | |
71 | |
57 | |
38 | |
36 |
User | Count |
---|---|
81 | |
67 | |
61 | |
46 | |
45 |