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
rockykb
Helper I
Helper I

Comparing and Calculating Data of two dates from a single column

Hi All,

 

I am trying to Compare and Calculate Data of two dates from a single date column i.e. the Net variance and Actual Variance.

For sample I have give below the Date COlumn and Employee Name so that at chosen date from slicer, the actual and net variance should pupulate.

Can someone help me with the dax. Reference image is below.

IMG_20200901_132238.jpg

8 REPLIES 8
amitchandak
Super User
Super User

@rockykb , refer if this blog can help

https://community.powerbi.com/t5/Community-Blog/Comparing-Data-Across-Date-Ranges/ba-p/823601

 

else

Can you share sample data and sample output in table format?

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Hi @amitchandak ,

 

Thanks for the response.

However the shared link ise useful when we want to aggregate at a given date and calculate.

But my ask is how to compare the values at given two dates from a single column?

Refer below;

 

DateEmployee
1/1/2019A
1/1/2019B
2/1/2019A
3/1/2019C
4/1/2019D
5/1/2019E
6/1/2019A
6/1/2019C
6/1/2019D
6/1/2019E

 

Desired Output 1
Base Date1/1/2019
Compare Date6/1/2019
  
Net varianceActual variance
21
 B

 

Desired Output 2
Base Date6/1/2019
Compare Date1/1/2019
  
Net varianceActual variance
-23
 C, D, E

@rockykb See my article on Mean Time Between Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/3395....
The basic pattern is:
Column = 
  VAR __Current = [Value]
  VAR __Previous = MAXX(FILTER('Table','Table'[Date] < EARLIER('Table'[Date])),[Value])
RETURN
  __Current - __Previous



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Hi @Greg_Deckler ,

 

Thank you for the response.

Request you to please refer below table for my problem statement.

 

My issue is I am able to calculate the employee # between two dates by comapring the names.

But when I using Group as a filter or in the Table then the count is getting increased.

Lets take an example from Table For Employee A.

For base date 6/1/19 and compare date 1/1/19, A's count should not come in Actual Variance. But if I put filter/slicer for Group. His count is coming as he has changed the group but I am trying to ignore this.

 

DateEmployeeGroup
1/1/2019AIndia
1/1/2019BUSA
2/1/2019AUSA
3/1/2019CUK
4/1/2019DCanada
5/1/2019EDenmark
6/1/2019AUSA
6/1/2019CUK
6/1/2019DCanada
6/1/2019EDenmark
7/1/2019GPoland
8/1/2019HChina
9/1/2019AIndia
10/1/2019BUSA

 

Desired Output 1
Base Date1/1/2019
Compare Date6/1/2019
  
Net varianceActual variance
21
 B

 

Desired Output 2
Base Date6/1/2019
Compare Date1/1/2019
  
Net varianceActual variance
-23
 C, D, E

@rockykb Is there missing data or am I missing something? Where does the variance come into play? How are you getting your expected output? I mean the logic of it? If you are saying, give me everybody that is in this first group that is not in this second group then you need to use EXCEPT.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Hi @Greg_Deckler ,

I used calculatetable to get the values for each dates (two dates: min and max).

Then I have counted the rows of the tables by comparing the values using filter condition.

This is giving me the desired output however when I am using the filter/slicer I am facing the error in count (as I have given the example of employee A).

@rockykb I need to see your calculation formulas. It is very likely that the proble lies, for examply if you are using something like ALL when calculating the minimum or the maximum. That can mess with the context from the slicer.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Hi @Greg_Deckler 

 

Below is the DAX used;

 

Actaul variance =
var base = CALCULATETABLE(
DISTINCT('Table'[Employee]),
FILTER(
'Table',
'Table'[Date]=SELECTEDVALUE('base_table'[Date])
)
)
var compair = CALCULATETABLE(
DISTINCT('Table'[Employee]),
FILTER(
'Table',
'Table'[Date]=SELECTEDVALUE('Compair_Table'[Date])
)
)
var result = COUNTROWS(
FILTER(
compair,NOT([Employee] in base)
)
)
return if(
ISBLANK(result),
0,
result)

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.