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
victoryamaykin
Frequent Visitor

Filter a DAX measure with dynamic date filters / Time Intelligence

I need to filter a calculated table to find the metric for a particular department of goods and a dynamic date range. The Sales Cycle should have a Sold % Quantity which is the total items sold divided by the number of items produced. 

These two numbers need to match: 

victoryamaykin_0-1710429282815.png

This DAX is not working: 

Sold % Qty Clothing = 

VAR _startSalesCycle = DATE(2024, 02, 04)

VAR _endSalesCycle = DATE(2024, 02, 27)

CALCULATE(

    [Sold % Qty],

    'Production Units by Week'[DepartmentName] = "Donated Clothing",

    DATESINPERIOD(Dates[Date], _startSalesCycle, _endSalesCycle, DAY

    )

)


Eventually, I want the start and end of the Sales Cycle to determine how this table gets filtered on a weekly basis. 

Which date filters should I use? 

1 REPLY 1
v-yanimei-msft
Community Support
Community Support

Hi @victoryamaykin  , 

Thank you for the relevant description of your problem. Based on your description, I may not have a good understanding of your needs. I don't know what the three dates you show represent and how you'd like to filter them. Based on my understanding, I give you the following steps to achieve the desired effect.

To match the two numbers in your picture, I will show you the steps:

1.The test table Production Units by Week:

vyanimeimsft_0-1710481849138.png

2.Modify the DAX code:

 

Sold % Qty Clothing =

LOOKUPVALUE('Production Units by Week'[Sold % Qty],'Production Units by Week'[DepartmentName],"Donated Clothing")

 

The DAX code can help you find the data what you want. Learn more about LOOKUPVALUE function (DAX) - DAX | Microsoft Learn.

3.The outcome is in the following picture.

vyanimeimsft_1-1710481867458.png

 

To filter the data between Start Next Sales Cycle and End Next Sales Cycle ( I guess you want ), I will show you the steps:

1.The test table Date:

vyanimeimsft_2-1710481902309.png

2. Right-click Production Units by Week, New Measure measure and input:

 

measure = 
VAR _1 = IF(SELECTEDVALUE('Date'[Date]) < MAX([Start Next Sales Cycle]) || SELECTEDVALUE('Date'[Date]) > MAX([End Next Sales Cycle]), 0, 1)
RETURN
_1

 

3. Right-click Production Units by Week, New Measure Sold % Qty 1 and input:

 

Sold % Qty 1 = IF([measure] = 1 , MAX([Sold % Qty]))

 

4. The outcome is in the following pictures.

vyanimeimsft_3-1710481976601.png

vyanimeimsft_4-1710481985624.png

vyanimeimsft_5-1710481999066.png

vyanimeimsft_6-1710482017671.png

You can adjust the date logic as needed to fit your scenario. Learn more about Create a relative date slicer or filter in Power BI - Power BI | Microsoft Learn.

If you have any challenges or other issues implementing this solution, can you share the specific data ( including table and model ) you have used in text and image format? In addition to this, you also need to determine if there are any specific filters or slicers applied to the report, as this may affect this calculation. This will help diagnose the problem more effectively.

 

Best Regards,
Caroline Mei
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.