The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
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