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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
janislv
Helper I
Helper I

Time intelligence methods for hourly calculations

So, here is a measure that works just fine when I'm using the Daily calendar. What could be the possible directions for doing the same when using Hourly calendar?

 

Cumulative sum =
CALCULATE (
    [Measure],
    CALCULATETABLE (
        SAMEPERIODLASTYEAR ( DATESYTD ( 'Daily calendar'[Date], "31/03" ))))

1 ACCEPTED SOLUTION
v-rzhou-msft
Community Support
Community Support

Hi @janislv ,

 

I tested your measure and I find that it will return the YTD sum of [Measure] after 03/31 by  in last year. If you want to do the same with Hourly , I think time intelligence functions don't support you to do this. Try this code.

Here I want to get YTD sum of values after 06/01 8:00:00.

My sample:

1.png

Measure:

 

Measure 3 = 
VAR _ADD1 = ADDCOLUMNS(ALL('Table'),"Year",YEAR('Table'[Date]),"Month",MONTH('Table'[Date]),"Day",DAY('Table'[Date]),"Hour",HOUR('Table'[Date]))
VAR _ADD2 = SUMMARIZE(_ADD1,[Year],"Sum", SUMX(FILTER(_ADD1,[Year]=EARLIER([Year])&&[Month]>=6&&[Day]>=1&&[Hour]>8),[Value]))
Return
SUMX(FILTER(_ADD2,[Year] = MAX('Daily calendar'[Year])-1),[Sum])

 

Result is as below.

1.png

Best Regards,
Rico Zhou

 

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

 

View solution in original post

3 REPLIES 3
v-rzhou-msft
Community Support
Community Support

Hi @janislv ,

 

I tested your measure and I find that it will return the YTD sum of [Measure] after 03/31 by  in last year. If you want to do the same with Hourly , I think time intelligence functions don't support you to do this. Try this code.

Here I want to get YTD sum of values after 06/01 8:00:00.

My sample:

1.png

Measure:

 

Measure 3 = 
VAR _ADD1 = ADDCOLUMNS(ALL('Table'),"Year",YEAR('Table'[Date]),"Month",MONTH('Table'[Date]),"Day",DAY('Table'[Date]),"Hour",HOUR('Table'[Date]))
VAR _ADD2 = SUMMARIZE(_ADD1,[Year],"Sum", SUMX(FILTER(_ADD1,[Year]=EARLIER([Year])&&[Month]>=6&&[Day]>=1&&[Hour]>8),[Value]))
Return
SUMX(FILTER(_ADD2,[Year] = MAX('Daily calendar'[Year])-1),[Sum])

 

Result is as below.

1.png

Best Regards,
Rico Zhou

 

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

 

CNENFRNL
Community Champion
Community Champion

Time intelligence functions address dataset at granularity of date.


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!

VahidDM
Super User
Super User

Hi @janislv 

 

Can you post sample data as text and expected output?
Not enough information to go on;

please see this post regarding How to Get Your Question Answered Quickly:
https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.
4. Relation between your tables

Appreciate your Kudos!!
LinkedIn:www.linkedin.com/in/vahid-dm/

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors