Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin 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.
Hello
I get a problem when comparing to dates, Is this instruction correct?
Solved! Go to 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.
Hi @PatrickByGecko ,
try DATE instead of DATEVALUE.
https://docs.microsoft.com/en-us/dax/date-function-dax
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
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.
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..
😞
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/
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..
Okay, these are the dates you are comparing
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
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
72 | |
70 | |
54 | |
38 | |
31 |
User | Count |
---|---|
83 | |
64 | |
63 | |
49 | |
45 |