guidance
5 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.4KViews0likes7CommentsUsing CALCULATE or not
I'm looking for some experienced guidnce on whether best practice is to use CALCULATE or not. See these two measures which both produce the correct result. Which is considered the right or best way to create this measure? OPTION 1: CALCULATE( SUMX( 'ITRDB Daily_ProjectFinancial', 'ITRDB Daily_ProjectFinancial'[MTD] ), 'ITRDB Daily_ProjectFinancial'[Dimension] = "Plan", NOT CONTAINSSTRING( 'ITRDB Daily_ProjectFinancial'[Budgetcomponent], "Total" ) ) OPTION 2: SUMX( FILTER( 'ITRDB Daily_ProjectFinancial', 'ITRDB Daily_ProjectFinancial'[Dimension] = "Plan" && NOT CONTAINSSTRING( 'ITRDB Daily_ProjectFinancial'[Budgetcomponent], "Total" ) ), 'ITRDB Daily_ProjectFinancial'[MTD] )Solved876Views0likes3CommentsCalculate Last Transaction Records
Hi, Within Power BI, I have a below table and I want to create another column which calculates Last Margin % for every records. If the customer A buys product A12 then for its Last Margin % is null and if same customer (i.e. A) buys same product (i.e. A12) then its Margin % will 30%. So my result table will be as below. I want to write DAX for this. Can some one help me on this?Solved4.8KViews0likes7Comments