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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
ChrisPBIUser
Helper III
Helper III

Compare data to same time previous day

Need assistance to display in a visual the number of sales made so far today with the same timeframe yesterday.

I have 2 columns, [DateTime] and [Sale] for example a row would be 29/11/2022 10:25:12 and 1.

 

So what I'm looking to do is compare the sales for today so far against the sales to the same time for for previous day.  I've had a look around and nothing really sticks out to help.

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

Hi  @ChrisPBIUser ,

I created some data:

vyangliumsft_0-1669771748335.png

Here are the steps you can follow:

1. Create measure.

Measure =
var _now=now()
var _nowstart =DATE(YEAR(_now),MONTH(_now),DAY(_now))+ TIME(0,0,0)
var _previous=DATE(YEAR(_now),MONTH(_now),DAY(_now)-1)+ TIME(HOUR(_now),MINUTE(_now),SECOND(_now))
var _previoustart =DATE(YEAR(_now),MONTH(_now),DAY(_now)-1)+ TIME(0,0,0)
var _nowsum=
SUMX(FILTER(ALL('Table'),'Table'[Date]>=_nowstart&&'Table'[Date]<=_now),[Amount])
var _previoussum=
SUMX(FILTER(ALL('Table'),'Table'[Date]>=_previoustart&&'Table'[Date]<=_previous),[Amount])
return
IF(
_nowsum > _previoussum ,"The amount today is larger than yesterday","The amount yesterday was larger than today")

2. Result:

vyangliumsft_1-1669771748336.png

 

Best Regards,

Liu Yang

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
ChrisPBIUser
Helper III
Helper III

Resolved this now by tweaking your dax, thanks again, @v-yangliu-msft 

v-yangliu-msft
Community Support
Community Support

Hi  @ChrisPBIUser ,

I created some data:

vyangliumsft_0-1669771748335.png

Here are the steps you can follow:

1. Create measure.

Measure =
var _now=now()
var _nowstart =DATE(YEAR(_now),MONTH(_now),DAY(_now))+ TIME(0,0,0)
var _previous=DATE(YEAR(_now),MONTH(_now),DAY(_now)-1)+ TIME(HOUR(_now),MINUTE(_now),SECOND(_now))
var _previoustart =DATE(YEAR(_now),MONTH(_now),DAY(_now)-1)+ TIME(0,0,0)
var _nowsum=
SUMX(FILTER(ALL('Table'),'Table'[Date]>=_nowstart&&'Table'[Date]<=_now),[Amount])
var _previoussum=
SUMX(FILTER(ALL('Table'),'Table'[Date]>=_previoustart&&'Table'[Date]<=_previous),[Amount])
return
IF(
_nowsum > _previoussum ,"The amount today is larger than yesterday","The amount yesterday was larger than today")

2. Result:

vyangliumsft_1-1669771748336.png

 

Best Regards,

Liu Yang

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

That's great, really appreciate your reply, but I missed off one column which is sales agent.  So I have, [SalesAgent], [DateTime],[Sales].  The [Sales] row will always be 1 as an Sales Agent will not be able to create more than one sale at a given moment in time.  I just can't tweak your DAX to include agent

 

ChrisPBIUser_0-1669801737418.png

 

 

 

 

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.