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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
edtm
Frequent Visitor

Custom Column for Relative Date Range Measures

What I am trying to do is to:

1) Calculate difference in unit sales between two date ranges
2) If units sold in date range 1 is less than units sold in date range 2, then a custom column is used to call this out with "Leakage".

 

This works if I use static range as below:

edtm_0-1710621565990.png

 

Dax for Product A  2022 is:

edtm_1-1710622236050.png

 

So, I wanted to do a similar analysis but using relative date range instead of statc date range.  The table looks like this:

edtm_2-1710622436683.png

Now, the units for the 2022 total uses this dax:

edtm_3-1710622528465.png

And, the units for 2023 total uses this dax:

edtm_4-1710622557760.png

The custom column that shows "Leakage" is thus:

edtm_0-1710724748122.png

 

However, there there should be "Leakage" labled for West region but it's blank.  I assume my dax in custom column above doesn't work with relative date ranges.  So, is there a way to get the Leakage custom column to show "Leakage" for Wetern Region in the table with relative date ranges?

Sample file is below:
Sample 

 

Thanks!

 

Update:

Adding what is ultimately what I am trying to achieve which is a filter that filters for Regions that have Decrease YOY Units in Product A and Increase YOY units in Product B which indicates possible conversion from Product A to B but using relative instead of static date DAX:

edtm_0-1710644899890.png

 




 

 

 

 

1 ACCEPTED SOLUTION

Hi @edtm ,
Here some steps that I want to share, you can check them if they suitable for your requirement.
Here is my test data:

vheqmsft_0-1711618418600.png

Create 2 calendar tables

Calendar 1 = VALUES('Table'[Year])
Calendar 2 = VALUES('Table'[Year])

Create measures

Selected by Calendar 1 = 
CALCULATE(
    MAX('Table'[Value]),
    FILTER(
        'Table',
        'Table'[Year] = SELECTEDVALUE('Calendar 1'[Year])
    )
)
Selected by Calendar 2 = 
CALCULATE(
    MAX('Table'[Value]),
    FILTER(
        'Table',
        'Table'[Year] = SELECTEDVALUE('Calendar 2'[Year])
    )
)
Value1 vs value 2 = [Selected by Calendar 1] - [Selected by Calendar 2]
Leakage or not = 
IF(
    [Value1 vs value 2] < 0,
    "Leakage",
    "increase"
)

Use the values of the two calendar tables as separate slicers
Final output

vheqmsft_1-1711618606305.png

 

Best regards,

Albert He

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

View solution in original post

3 REPLIES 3
v-heq-msft
Community Support
Community Support

Hi @edtm ,

Based on your description, I can understand that you mean you want to dynamically determine the range and calculate the difference of the dates while making a comment on the positive and negative values. Unfortunately, the pbix file you provided cannot be opened. Please provide your complete data in table or excel format so that we can help you faster. Please hide sensitive information in advance.

 

Best regards,

Albert He

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

Thank you for looking into my question. 

I just tested downloading the sample file and was able to open it.  At first I was like... wat's this? but then there's the download button:

edtm_0-1710737883774.png

I am sure this didn't get past you but not sure why else the file can't be accessed. 

Here's the base table sample data I put together in excel.

Excel Sample 
However, it might not be useful as without the PBIX file you can't see how I am I using it.

(But, I guess you could come up with your own method.)

Hi @edtm ,
Here some steps that I want to share, you can check them if they suitable for your requirement.
Here is my test data:

vheqmsft_0-1711618418600.png

Create 2 calendar tables

Calendar 1 = VALUES('Table'[Year])
Calendar 2 = VALUES('Table'[Year])

Create measures

Selected by Calendar 1 = 
CALCULATE(
    MAX('Table'[Value]),
    FILTER(
        'Table',
        'Table'[Year] = SELECTEDVALUE('Calendar 1'[Year])
    )
)
Selected by Calendar 2 = 
CALCULATE(
    MAX('Table'[Value]),
    FILTER(
        'Table',
        'Table'[Year] = SELECTEDVALUE('Calendar 2'[Year])
    )
)
Value1 vs value 2 = [Selected by Calendar 1] - [Selected by Calendar 2]
Leakage or not = 
IF(
    [Value1 vs value 2] < 0,
    "Leakage",
    "increase"
)

Use the values of the two calendar tables as separate slicers
Final output

vheqmsft_1-1711618606305.png

 

Best regards,

Albert He

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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