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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply

Probleme when Evaluating dates

Hello

I get a problem when comparing to dates, Is this instruction correct?

 
VAR _DateBeginMonth = DATEVALUE("01/" & MONTH(TODAY()) & "/" & YEAR(TODAY()))
VAR _DateBeginFinal = if ( 'TABLE'[DATE BEGIN] <= _DateDebutMonth ; _DateDebutMonth; 'TABLE'[DATE BEGIN] )
 
Because this comparison is always false though I'm sure 'TABLE'[DATE BEGIN] is bigger than _DateDebutMonth.
So I suppose I have a problem of syntax...
1 ACCEPTED SOLUTION

Hi

I did put my conditions inside the FIlter command and it is OK. It is not a beautiful code but it works...

Thank you again.

View solution in original post

8 REPLIES 8
mwegener
Most Valuable Professional
Most Valuable Professional

Hi @PatrickByGecko ,

 

try DATE instead of DATEVALUE.

https://docs.microsoft.com/en-us/dax/date-function-dax

 

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast - Power BI Tutorials


 

I did this way

VAR _DateBeginMonth = DATE( YEAR(TODAY()); MONTH(TODAY()) ; 1)
But the comparison gives the same, is always false though I'm sure 'TABLE'[DATE BEGIN] is bigger.
mwegener
Most Valuable Professional
Most Valuable Professional

Hi @PatrickByGecko ,

 

your formula 'TABLE'[DATE BEGIN] <= _DateDebutMonth says 'TABLE'[DATE BEGIN] is less or equal to _DateDebutMonth and if 'TABLE'[DATE BEGIN] is bigger than _DateDebutMonth this is false.

 

 

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast - Power BI Tutorials


You are right, the problem is somewhere else underneath =>

 

VAR _DateBeginMonth = DATE( YEAR(TODAY()); MONTH(TODAY()) ; 1)
VAR DateEndMonth = DATE( YEAR(TODAY()); MONTH(TODAY()) ; 30)
VAR _DateBeginAbsence = if ( 'TABLE'[DATE BEGIN] <= _DateBeginMonth ; _DateBeginMonth; 'TABLE'[DATE BEGIN])
VAR _DateEndAbsence = if ( 'TABLE'[DATE END] > DateEndMonth ; DateEndMonth; 'TABLE'[DATE END])

VAR _NbrDayAbsenceMaladie = SUMX(FILTER('TABLE';'TABLE'[COLLABORATEURId]=EARLIER('TABLE'[COLLABORATEURId]) && ('TABLE'[TYPE COLLAB] = "CDI" || 'TABLE'[TYPE COLLAB] = "CDD") && 'TABLE'[CODE PROJET] = "MALADIE01" ); DATEDIFF(_DateBeginAbsence;_DateEndAbsence;day)+1)
VAR _NbrDayAbsenceChomage = SUMX(FILTER('TABLE';'TABLE'[COLLABORATEURId]=EARLIER('TABLE'[COLLABORATEURId]) && ('TABLE'[TYPE COLLAB] = "CDI" || 'TABLE'[TYPE COLLAB] = "CDD") && 'TABLE'[CODE PROJET] = "CHOMAGE01" ); DATEDIFF(_DateBeginAbsence;_DateEndAbsence;day)+1)

 

The problem is that my variables can't be taken in account in the FILTER function only for the lines of the tables where there is "MALADIE01" and "CHOMAGE01" lines. The DATEDIFF function changes for each line of my table that I don't want.

Note that the FILTER works if I replace the variables VAR_ by the the real names of the column => DATEDIFF(TABLE'[DATE BEGIN];'TABLE'[DATE END];day)+1). Only "MALADIE01" and "CHOMAGE01" lines are treated for the DateDiff.

But I loose my two conditions in green..

😞

mwegener
Most Valuable Professional
Most Valuable Professional

Hi @PatrickByGecko,

 

i think you have to use the DAX variables inside the iterator SUMX...

 

VAR _DateBeginMonth = DATE( YEAR(TODAY()); MONTH(TODAY()) ; 1)
VAR DateEndMonth = DATE( YEAR(TODAY()); MONTH(TODAY()) ; 30)

VAR _NbrDayAbsenceMaladie = SUMX( FILTER('TABLE';'TABLE'[COLLABORATEURId]=EARLIER('TABLE'[COLLABORATEURId]) && ('TABLE'[TYPE COLLAB] = "CDI" || 'TABLE'[TYPE COLLAB] = "CDD") && 'TABLE'[CODE PROJET] = "MALADIE01" );

VAR _DateBeginAbsence = if ( 'TABLE'[DATE BEGIN] <= _DateBeginMonth ; _DateBeginMonth; 'TABLE'[DATE BEGIN])
VAR _DateEndAbsence = if ( 'TABLE'[DATE END] > DateEndMonth ; DateEndMonth; 'TABLE'[DATE END])

RETURN

DATEDIFF(_DateBeginAbsence;_DateEndAbsence;day)+1)
VAR _NbrDayAbsenceChomage = SUMX( FILTER('TABLE';'TABLE'[COLLABORATEURId]=EARLIER('TABLE'[COLLABORATEURId]) && ('TABLE'[TYPE COLLAB] = "CDI" || 'TABLE'[TYPE COLLAB] = "CDD") && 'TABLE'[CODE PROJET] = "CHOMAGE01" );

VAR _DateBeginAbsence = if ( 'TABLE'[DATE BEGIN] <= _DateBeginMonth ; _DateBeginMonth; 'TABLE'[DATE BEGIN])
VAR _DateEndAbsence = if ( 'TABLE'[DATE END] > DateEndMonth ; DateEndMonth; 'TABLE'[DATE END])

RETURN

DATEDIFF(_DateBeginAbsence;_DateEndAbsence;day)+1)

 

https://www.kasperonbi.com/using-dax-variables-in-iterators/

 

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast - Power BI Tutorials


Hi

I did put my conditions inside the FIlter command and it is OK. It is not a beautiful code but it works...

Thank you again.

 

When I display the values so as to check

VAR _DateBeginMonth = 43922 and 'TABLE'[DATE BEGIN] = 43942. So the problem must coming from the syntax of comparison. I think..

 

mwegener
Most Valuable Professional
Most Valuable Professional

Okay, these are the dates you are comparing

Int-Date.png

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast - Power BI Tutorials


Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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