show and tell
231 TopicsDAX and leap year, date range
Been researching this a while. Its not the usual Year on Year, and it not finding a corresponding 29th Feb but the period of a date range calculated. I am trying to bring in a count to then subtract that from the total. I've found something useful via Colin Maitland from 4 years ago but having problems finalising it. Code is: Its the removefilters & datesbetween having difficulty with. Even if I resolved that I'm not sure it will provide the solution so was looking for any other ideas. Thanking you calc = VAR _MAX_DATE = MAX ( 'Date'[Date], ) VAR _DAYS_IN_YEAR = IF ( NOT ISBLANK ( _MAX_DATE ), SWITCH ( TRUE(), // Is Max Date Year a Leap Year? DATEDIFF ( DATE ( YEAR ( _MAX_DATE ), 02, 28 ), DATE ( YEAR ( _MAX_DATE ), 03, 01 ), DAY ) = 2, IF ( _MAX_DATE >= DATE ( YEAR ( _MAX_DATE ), 02, 29 ), // NOTE: Compare with 29/02 of the highest selected Year here. 366, // Include 365 Days plus 29th February in the highest selected Year. 365 ), // Is Max Date Previous Year a Leap Year? DATEDIFF ( DATE ( YEAR ( _MAX_DATE ) - 1, 02, 28 ), DATE ( YEAR ( _MAX_DATE ) - 1, 03, 01 ), DAY ) = 2, IF ( _MAX_DATE <= DATE ( YEAR ( _MAX_DATE ), 02, 28 ), // NOTE: Compare with 28/02 of the highest selected Year here. 366, // Include 365 Days plus 29th February in the previous Year to the highest selected Year. 365 ), // Not a Leap Year 365 ) ) VAR _MIN_DATE = IF ( NOT ISBLANK ( _MAX_DATE ), ( _MAX_DATE - _DAYS_IN_YEAR ) + 1 // Adjust by one Day to ensure that same date as Max Date from previous Year is not included. ) VAR _RESULT = IF ( NOT ISBLANK ( _MAX_DATE ), CALCULATE ( SELECTEDMEASURE(), REMOVEFILTERS ( 'Date Range' ), DATESBETWEEN ( 'Date'[Date], _MIN_DATE, _MAX_DATE ) ) ) RETURN _RESULT //In this example, if there was no need to ensure that 365 days plus the 29th of February needed to be included in this calculation, then the VAR _DAYS_IN_YEAR = part of the formula could simply be changed to VAR _DAYS_IN_YEAR = 365.Solved2.2KViews0likes5CommentsDAX switch but using containsstring
Is there a way to have CONTAINSSTRING in the below instead, as using IN as part of the VAR _Name requires an exact, and I have some examples elsewhere where it would be easier to use containsstring. I've tried a few different IF CONTAINSSTRING in places, and substituted TRUE but can't get it to work Result = VAR _Name = 'Table1'[Name] RETURN SWITCH( TRUE(), _Name IN {"South"}, "30", _Name IN {"North"}, "28", _Name IN {"East"}, "22", _Name IN {"West"}, "20", "" ) thanks in advanceSolved972Views1like2Commentsrows split, but merging response results within table -- happy it repeats
Is there a measure that would be able to perform the "overall" result in red, from the associated table data. I would want it to be visual in the table, happy for the repeats, as having consolidated summary is useful when assessing. thanks, [Table] Campaign Number Responded View campaign count campaign&view responded type count view&responded type count overall_show across all rows - merged result 10021 Rep1 15/05/2025 Agreed 9 10021Agreed 6 Agreed 6 Agreed 6, Disagreed 2, Incomplete 1 10021 Rep2 18/05/2025 Agreed 9 10021Agreed 6 Agreed 6 Agreed 6, Disagreed 2, Incomplete 1 10021 Rep3 21/05/2025 Agreed 9 10021Agreed 6 Agreed 6 Agreed 6, Disagreed 2, Incomplete 1 10021 Rep4 21/05/2025 Disagreed 9 10021Disagreed 2 Disagreed 2 Agreed 6, Disagreed 2, Incomplete 1 10021 Rep5 26/05/2025 Agreed 9 10021Agreed 6 Agreed 6 Agreed 6, Disagreed 2, Incomplete 1 10021 Rep6 29/05/2025 Agreed 9 10021Agreed 6 Agreed 6 Agreed 6, Disagreed 2, Incomplete 1 10021 Rep7 30/05/2025 Disagreed 9 10021Disagreed 2 Disagreed 2 Agreed 6, Disagreed 2, Incomplete 1 10021 Rep8 30/05/2025 Incomplete 9 10021Incomplete 1 Incomplete 1 Agreed 6, Disagreed 2, Incomplete 1 10021 Rep9 30/05/2025 Agreed 9 10021Agreed 6 Agreed 6 Agreed 6, Disagreed 2, Incomplete 1 12524 Rep1 12/03/2025 Disagreed 1 12524Disagreed 1 Disagreed 1 Disagreed 1 9931 Rep1 25/01/2024 Agreed 2 9931Agreed 1 Agreed 1 Agreed 1, Incomplete 1 9931 Rep2 27/01/2024 Incomplete 2 9931Incomplete 1 Incomplete 1 Agreed 1, Incomplete 1Solved1.4KViews0likes7CommentsDAX to de-duplicate text string?
Would it be possible to get DAX de-duplicating a text string? In the example below - or any suggestions on alternate ways, but still using DAX π thanks in advance Address Area Distribution string = CONCATENATEX(FILTER(('Table'),'Table'[Address]=EARLIER('Table'[Address])),'Table'[Area],"; ") would then like it de-duplicated -- but wondered if DAX could facilitate? George Street 1st Floor Zone 3 1st Floor; 1st Floor; 2nd Floor 1st Floor; 2nd Floor George Street 2nd Floor Zone 1 1st Floor; 1st Floor; 2nd Floor 1st Floor; 2nd Floor George Street 1st Floor Zone 5 1st Floor; 1st Floor; 2nd Floor 1st Floor; 2nd Floor Lime Walk Basement Zone 7 Basement; Basement Basement Lime Walk Basement Zone 4 Basement; Basement Basement Hope Avenue Basement Zone 2 1st Floor; 1st Floor; Basement Basement; 1st Floor Hope Avenue 1st Floor Zone 8 1st Floor; 1st Floor; Basement Basement; 1st Floor Hope Avenue 1st Floor Zone 5 1st Floor; 1st Floor; Basement Basement; 1st Floor Market Square 2nd Floor Zone 6 2nd Floor 2nd FloorSolved1KViews0likes4Commentsdummy table, and to introduce a condition so only return subset of rows
I have created an offshoot dummy table but only want to include a certain subset - say the original table has 20000 rows, I just want to return around 500 that meet a set criteria. Would the table be able to provide for that condition, incorporating SELECTCOLUMNS ? I've tried to play around with the below but can't get it to accept. Streamlined version below. Looking for it to only return those where --- IF 'Table'[Company]="Company4" DUMMYTABLE = SELECTCOLUMNS( Table, "Ref", 'Table'[Reference], "From", 'Table'[From], "To", 'Table'[To] )Solved721Views0likes2CommentsRANK indexing with condition
Hi, have been looking at indexing again, and whether some sequencing conditions would be achievable. For (see snip below): RAND = RAND() RANK = RANKX(ALL(Table),Table[RAND]) RANK INC = IF(Table[isCurrent]="No",RANKX(ALL(Table),Table[RAND])) Is it possible to in the RANK INC not have it skip the excluded numbers and keep the sequence running without number gaps. Thought about && Table[isCurrent]="No" in RANK but can't get it right. Or is RANKX not going to be the best option to fulfil? Separately, I was then working on 3 digits to make up the number in RANK INC to be a full 3 digit sequence with leading zeroes. Still learning switch but would switch enable length decision and prefix 00 (for 1), 0 (for 2). Thanks,Solved878Views0likes4CommentsIF statement and conditions
Hello, what would be the best way to run both these in DAX within the same statement. Switch / nested? I can't quite work it through, grateful for pointers as a newbie. Although only 2 conditions (at the moment), and looked at OR || as well, not sure on most appropriate method. IF(CONTAINSSTRING(Table[CompanyNumber],"Company2"),IF(Table[Letter Received]="No" && ISBLANK(Table[Responded], IF(Table[CompanyNumber]<>"Company2"),IF(Table[Letter Received]<>"No" && ISBLANK(Table[Responded]), "Check", "Pass" )Solved974Views0likes5CommentsIssue with Conditional Formatting in Matrix Visual
Hi Team, Hope you're all doing well. I was working on applying conditional formatting in the Matrix visual, where I have a column called "ppk" and I am applying the following criteria to achieve color coding using DAX. Using this DAX (with averages included): DAX PPK_Conditional_Color_heatmap = VAR Ppk_Value = AVERAGE('PPK'[ppk_vl]) // No COALESCE applied VAR StdDev_Value = AVERAGE('PPK'[stddev_vl]) // No COALESCE applied RETURN SWITCH( TRUE(), Ppk_Value = 0 && StdDev_Value = 0, "#808080", // Grey for NULL Ppk & StdDev is Blank Ppk_Value = 0 && StdDev_Value = 0, "#ADD8E6", // Light Blue for NULL Ppk & StdDev = 0 Ppk_Value >= 1.33, "#69b764", // Green Ppk_Value >= 1.00 && Ppk_Value < 1.33, "#ffc156", // Yellow Ppk_Value < 1.00, "#d82526" // Red ) The criteria for coloring are as follows: Ppk >= 1.33 β Green Ppk >= 1.00 && Avg_Ppk < 1.33 β Yellow Ppk < 1.00 β Red PPK = NULL & StdDev_Vl = 0 β Light Blue PPK = NULL & StdDev_Vl = Blank β Grey However, after applying the formula, the grey and light blue colors are not showing as expected. I believe the issue is that when the cell is empty, the conditional formatting is not triggering. This might be because blank values arenβt being accounted for correctly in the DAX expression. Has anyone encountered this issue, or do you have any suggestions on how to address it? Looking forward to your inputs. Thanks & Regards, Hk1KViews0likes5CommentsHow to debug DAX measure that result in table
Hello, As the subject says, am wondering if there's a way to know the result/output of a measure that resulted in a table? For example, I have a measure below, as you can see, I have _table1. If I want to break down the formula and see the output, from FILTER function, all the way to the AddColumns, is there a way to do it? Thanks MEASURE = VAR _obj = SELECTEDVALUE ( 'Table'[obj code] ) VAR _cost = SELECTEDVALUE ( 'Table'[cost code] ) VAR _id = SELECTEDVALUE ( 'Table'[id] ) VAR _table1 = ADDCOLUMNS ( 'tbl_Tier1', "c1", SUMX ( FILTER ( mirrorFactTableWithAllCostCodes, [id] = EARLIER ( tbl_Tier1[T1_From] ) && [obj code] = _obj && [cost code] = _cost ), [Column] ) * [T1_Alloc] ) VAR _table2 = ADDCOLUMNS ( 'tbl_Tier2', "c1", VAR _result = ( SUMX ( FILTER ( _table1, [T1_To] = EARLIER ( tbl_Tier2[T2_From] ) ), [c1] ) + SUMX ( FILTER ( 'mirrorFactTableWithAllCostCodes', [id] = EARLIER ( tbl_Tier2[T2_From] ) && [obj code] = _obj && [cost code] = _cost ), [Column] ) ) * [T2_Alloc] RETURN IF ( ISBLANK ( _result ), 0, _result ) ) VAR _table3 = ADDCOLUMNS ( 'tbl_Tier3', "c1", VAR _result = ( SUMX ( FILTER ( _table2, [T2_To] = EARLIER ( tbl_Tier3[T3_From] ) ), [c1] ) + SUMX ( FILTER ( 'mirrorFactTableWithAllCostCodes', [id] = EARLIER ( tbl_Tier3[T3_From] ) && [obj code] = _obj && [cost code] = _cost ), [Column] ) ) * [T3_Alloc] RETURN IF ( ISBLANK ( _result ), 0, _result ) ) RETURN SUMX ( FILTER ( _table3, [T3_To] = _id ), [c1] ) + SUMX ( FILTER ( 'mirrorFactTableWithAllCostCodes', [id] = _id && [cost code] = _cost && [obj code] = _obj ), [Column] )993Views0likes3CommentsAccrued Vacation formula in power BI
Hi, I am working on tracking PTOs in power Bi. I want to create a DAX query on the basis of below parameters 1.) 0 β 2 years = 10 days per year 2 β 10 years = 15 days per year 10+ = 20 days per year 2) If anyone joins on or before 15th of a particular month, then he/she gets leaves for that particular month else from next month onwards. 3) Also, if any employee hits milestone in the current year, e.g. if one of the employee who joined on 9-aug-2022 is completing 2 yr milestone oln 9-aug-2024, ideally his accrual should be =((10/12)*7) + ((15/12)*4)=10.83 . I have tried using below formula but somehow it is not giving me desired output. Let me know if anyone has any inputs or suggestions... Accrued Vacation = VAR StartDate = SELECTEDVALUE('Employee Roster'[Start Date]) VAR CurrentDate = TODAY() VAR CurrentYear = YEAR(CurrentDate) VAR StartYear = YEAR(StartDate) VAR StartMonth = MONTH(StartDate) VAR CurrentMonth = MONTH(CurrentDate) VAR StartDay = DAY(StartDate) VAR Tenure = DATEDIFF(StartDate, CurrentDate, YEAR) VAR AnniversaryDate = DATE(YEAR(StartDate) + Tenure, MONTH(StartDate), DAY(StartDate)) -- Determine Monthly Accrual Rates VAR MonthlyAccrualBefore = SWITCH( TRUE(), Tenure < 2, 10 / 12, Tenure < 10, 15 / 12, 20 / 12 ) VAR MonthlyAccrualAfter = SWITCH( TRUE(), Tenure + 1 < 2, 10 / 12, Tenure + 1 < 10, 15 / 12, 20 / 12 ) -- Determine Effective Date for New Joins VAR EffectiveDate = IF(StartYear = CurrentYear, IF(StartDay <= 15, DATE(CurrentYear, StartMonth, 1), EOMONTH(StartDate, 0) + 1), DATE(CurrentYear, 1, 1) ) -- Calculate Months Before and After Anniversary VAR MonthsBeforeAnniversary = IF( AnniversaryDate <= CurrentDate, DATEDIFF(EffectiveDate, AnniversaryDate, MONTH), DATEDIFF(EffectiveDate, CurrentDate, MONTH) ) VAR MonthsAfterAnniversary = IF( AnniversaryDate <= CurrentDate, DATEDIFF(AnniversaryDate, CurrentDate, MONTH), 0 ) -- Calculate Total Accrued Vacation VAR AccruedVacation = IF( DAY(AnniversaryDate) <= 15, (MonthlyAccrualBefore * MonthsBeforeAnniversary) + (MonthlyAccrualAfter * (MonthsAfterAnniversary + 1)), (MonthlyAccrualBefore * (MonthsBeforeAnniversary + 1)) + (MonthlyAccrualAfter * MonthsAfterAnniversary) ) -- Adjust for the specific case where the anniversary date is after the 15th of the month VAR FinalAccruedVacation = IF( DAY(AnniversaryDate) > 15, (MonthlyAccrualBefore * MonthsBeforeAnniversary) + (MonthlyAccrualAfter * MonthsAfterAnniversary), AccruedVacation ) -- Ensure correct calculation for milestones within the current year VAR CorrectedAccruedVacation = IF( Tenure = 1 || Tenure = 9, (MonthlyAccrualBefore * (MonthsBeforeAnniversary + 1)) + (MonthlyAccrualAfter * MonthsAfterAnniversary), FinalAccruedVacation ) RETURN ROUND(CorrectedAccruedVacation, 2)Solved1.6KViews0likes6Comments