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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Calculations in Direct Query mode according power production per day, month, etc.

Although I've managed to achieve DAX calculations with static Excel files according the following problem, I couldn't achieve this in Direct Query mode. Here is the scenario:

 

Through Azure's Stream Analytics we store in SQL Server Database some values referring to solar panel energy production.

Sampling rate is about every hour. We want to calculate the daily (weekly, monthly, yearly... ) production by substracting the maximum of each time value with the maximum of the previous same period.

Here is a screenshot of Power Query editor

daily-last-values.png

 

You can the last value recorder in 11/02/2023. We want to substract this value from the respective last value of 12/02/2023 in order to have the daily production.

 

Does anyone has any ideas?

 

Thanks in advance

 

2 REPLIES 2
Anonymous
Not applicable

@amitchandak 

 

Sorry for the delayed answer... Thank you for your suggestions.

Your proposals

 

MTD = CALCULATE(Max(Table[Value]),DATESMTD('Date'[Date]))
last MTD = CALCULATE(Max(Table[Value]),DATESMTD(dateadd('Date'[Date],-1,MONTH)))

 

are the ones I do want, but I have some further questions.

 

The real scenario is this:

I have ten (10) different production values, INV1, INV2, INV3.... INV10. I do calculate the MTD value and the Last MTD value as suggested for INV1, in a new measure I calculate the MTD - Last MTD difference to have as a result the monthly production of INV1. This difference is the final number I want to have it on a visual, namely the energy production.

 

  • Do you believe that the final solution is to have the same for calculations for INV2, INV3 and so on? (Three for each one?).
  • Have in mind that I have to calculate this for day, month, 6months, year.
  • The final visual (pretty draft) is the one I have below. A slicer with date values (daily, monthly, weekly, yearly etc.) and a column chart respectively.

MAIN REPORT.png

 I also remind that data are acquired in direct query mode.

 

Thanks in advance.

amitchandak
Super User
Super User

@Anonymous , Based on what I got, You can use time intelligence

 


MTD = CALCULATE(Max(Table[Value]),DATESMTD('Date'[Date]))
last MTD = CALCULATE(Max(Table[Value]),DATESMTD(dateadd('Date'[Date],-1,MONTH)))

 

Same way you can get Qtr, year

 

You can also try offset function

Power BI Offset Compare Categories, Time Intelligence MOM, QOQ, and YOY: https://youtu.be/5YMlkDNGr0U

 

Time Intelligence, Part of learn Power BI https://youtu.be/cN8AO3_vmlY?t=27510
Time Intelligence, DATESMTD, DATESQTD, DATESYTD, Week On Week, Week Till Date, Custom Period on Period,
Custom Period till date: https://youtu.be/aU2aKbnHuWs&t=145s

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors
Top Kudoed Authors