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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
bideveloper555
Helper IV
Helper IV

SamePeriodLastYear for DateTime

hi

 i am trying to get value for sameperiodlastyear using datetime column in date table.

 

i have column Datetime in table date and where the data is located transcationdate,no of transcation.

i want to drill down year,month,date,hours too.

Previous Year = CALCULATE(SUM('TransTable'[no.of trans]),SAMEPERIODLASTYEAR('DateTime'[DateTime]) )

this is not working as there are duplicates dates due to hours.

below is the same data and desired output.

DateTime table   Transcation Table   Desired output 
DateTimeDate IDTransDateno. of trans   
01/01/2020 01:0001/01/2020 101/01/2020 01:0010  CurrentyearLast year
01/01/2020 02:0001/01/2020 201/01/2020 02:0020 01/01/2020 01:001015
01/01/2020 03:0001/01/2020 301/01/2020 03:0030 01/01/2020 02:002030
01/01/2019 01:0001/01/2019 401/01/2019 01:0015 01/01/2020 03:003040
01/01/2019 02:0001/01/2019 501/01/2019 02:0030    
01/01/2019 03:0001/01/2019 601/01/2019 03:0040    
          
          
1 ACCEPTED SOLUTION
v-deddai1-msft
Community Support
Community Support

Hi @bideveloper555 ,

 

Time intelligence didn't work for datetime type, you can create a calculated column for lastyeardatetime and convert it to datetime type:

 

lastyeardate = var _date = DATE(YEAR(Transcation[TransDate])-1,MONTH(Transcation[TransDate]),DAY(Transcation[TransDate])) var time =FORMAT(Transcation[TransDate],"hh:mm:ss") return _date&" "&time 

 

Capture3.PNG

 

Then create the following measure:

Currentyear = SUM(Transcation[no. of trans])

Lastyear = CALCULATE([Currentyear],FILTER(ALL(Transcation),Transcation[TransDate] = MAX(Transcation[lastyeardate])))

 

Capture4.PNG

For more details, please refer to the pbix file: https://qiuyunus-my.sharepoint.com/:u:/g/personal/pbipro_qiuyunus_onmicrosoft_com/EW3eGcCbj21LjU_e0H...

 

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

 

Best Regards,

Dedmon Dai

View solution in original post

3 REPLIES 3
v-deddai1-msft
Community Support
Community Support

Hi @bideveloper555 ,

 

Time intelligence didn't work for datetime type, you can create a calculated column for lastyeardatetime and convert it to datetime type:

 

lastyeardate = var _date = DATE(YEAR(Transcation[TransDate])-1,MONTH(Transcation[TransDate]),DAY(Transcation[TransDate])) var time =FORMAT(Transcation[TransDate],"hh:mm:ss") return _date&" "&time 

 

Capture3.PNG

 

Then create the following measure:

Currentyear = SUM(Transcation[no. of trans])

Lastyear = CALCULATE([Currentyear],FILTER(ALL(Transcation),Transcation[TransDate] = MAX(Transcation[lastyeardate])))

 

Capture4.PNG

For more details, please refer to the pbix file: https://qiuyunus-my.sharepoint.com/:u:/g/personal/pbipro_qiuyunus_onmicrosoft_com/EW3eGcCbj21LjU_e0H...

 

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

 

Best Regards,

Dedmon Dai

amitchandak
Super User
Super User

@bideveloper555 , this will not work with date time, You can only use date

Create a date column

Date = [DateTime].date
or
Date = date(year([DateTime ]),month([DateTime ]),day([DateTime ]))

 

Join date with date of date table and then try

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.

hi,

i created a date table and created date column in fact table.joined both date columns but still i cant drill down to HH.I can drill YY>Q>MMM>D but Hours.

when i marked Date table as Date,drill down doesnt work at all.

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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