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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Meep
Frequent Visitor

Compare multiple date fields to a value that can be selected manually using DAX

Hi, 

 

I am trying to create a table with some monthly ratios which use different dates from my dataset and I do not know if that is possible. A normal parameter does not seem to do the trick and I want to know if I could have a dropdown where I can select a month and a year or the days within a month in two variables to compare them against the dates used for the ratios. 

 

OpportunityRequest DateProcess DateClose date
101/06/202210/10/202225/10/2022
220/06/202230/06/202201/08/2022
305/08/202121/09/202101/01/2022
421/04/202006/06/202012/12/2020
508/10/202212/10/202221/10/2022
614/06/202124/07/202102/03/2022
723/01/202212/06/202224/06/2022
825/04/202105/05/2021

12/01/2022

 

As you can see above, there are multiple dates and the ratios I want to calculate vary between process booked date and close date.

 

I would like to know if I can somehow store a specific month, say 03/2021 and see how many opportunities have been processed before that date and how many opportunities have been closed afterwards by implemeting this parameter in a DAX function.

 

https://www.youtube.com/watch?v=SMHbMhX1Ggg&ab_channel=DhruvinShah

 

This video seems helpful in terms of how to structure the DAX formula, but my goal is to do something similar but instead of typing the date every time, I can just tie it to a paramater that my team can change and adapt the formulas as they are tied to the said parameter. 

 

Thank you in advance

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi  @Meep ,

Here are the steps you can follow:

1. Create measure.

Count Process Date =
VAR _selectyear =
    SELECTEDVALUE ( 'Table 2'[Date].[Year] )
VAR _selectmonth =
    SELECTEDVALUE ( 'Table 2'[Date].[Month] )
VAR _selectday =
    SELECTEDVALUE ( 'Table 2'[Date].[Day] )
VAR _selectnumber =
    MAXX (
        FILTER ( ALL ( 'Table 2' ), FORMAT ( 'Table 2'[Date], "mmmm" ) = _selectmonth ),
        MONTH ( 'Table 2'[Date] )
    )
RETURN
    SWITCH (
        TRUE (),
        HASONEVALUE ( 'Table 2'[Date].[Year] )
            && HASONEVALUE ( 'Table 2'[Date].[Month] )
            && HASONEVALUE ( 'Table 2'[Date].[Day] ),
            COUNTX (
                FILTER (
                    ALL ( 'Table' ),
                    'Table'[Process Date] <= DATE ( _selectyear, _selectnumber, _selectday )
                ),
                [Opportunity]
            ),
        HASONEVALUE ( 'Table 2'[Date].[Year] )
            && HASONEVALUE ( 'Table 2'[Date].[Month] ),
            COUNTX (
                FILTER (
                    ALL ( 'Table' ),
                    'Table'[Process Date] <= DATE ( _selectyear, _selectnumber, 1 )
                ),
                [Opportunity]
            ),
        HASONEVALUE ( 'Table 2'[Date].[Year] ),
            COUNTX (
                FILTER ( ALL ( 'Table' ), YEAR ( 'Table'[Process Date] ) <= _selectyear ),
                [Opportunity]
            ),
        0
    )
Count Close Date =
VAR _selectyear =
    SELECTEDVALUE ( 'Table 2'[Date].[Year] )
VAR _selectmonth =
    SELECTEDVALUE ( 'Table 2'[Date].[Month] )
VAR _selectday =
    SELECTEDVALUE ( 'Table 2'[Date].[Day] )
VAR _selectnumber =
    MAXX (
        FILTER ( ALL ( 'Table 2' ), FORMAT ( 'Table 2'[Date], "mmmm" ) = _selectmonth ),
        MONTH ( 'Table 2'[Date] )
    )
RETURN
    SWITCH (
        TRUE (),
        HASONEVALUE ( 'Table 2'[Date].[Year] )
            && HASONEVALUE ( 'Table 2'[Date].[Month] )
            && HASONEVALUE ( 'Table 2'[Date].[Day] ),
            COUNTX (
                FILTER (
                    ALL ( 'Table' ),
                    'Table'[Close date] > DATE ( _selectyear, _selectnumber, _selectday )
                ),
                [Opportunity]
            ),
        HASONEVALUE ( 'Table 2'[Date].[Year] )
            && HASONEVALUE ( 'Table 2'[Date].[Month] ),
            COUNTX (
                FILTER (
                    ALL ( 'Table' ),
                    'Table'[Close date] > DATE ( _selectyear, _selectnumber, 1 )
                ),
                [Opportunity]
            ),
        HASONEVALUE ( 'Table 2'[Date].[Year] ),
            COUNTX (
                FILTER ( ALL ( 'Table' ), YEAR ( 'Table'[Close date] ) > _selectyear ),
                [Opportunity]
            ),
        0
    )
ratios =
DIVIDE(
    [Count Process Date],[Count Close Date])

2. Result:

vyangliumsft_0-1668393538600.png

 

Best Regards,

Liu Yang

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

2 REPLIES 2
Anonymous
Not applicable

Hi  @Meep ,

Here are the steps you can follow:

1. Create measure.

Count Process Date =
VAR _selectyear =
    SELECTEDVALUE ( 'Table 2'[Date].[Year] )
VAR _selectmonth =
    SELECTEDVALUE ( 'Table 2'[Date].[Month] )
VAR _selectday =
    SELECTEDVALUE ( 'Table 2'[Date].[Day] )
VAR _selectnumber =
    MAXX (
        FILTER ( ALL ( 'Table 2' ), FORMAT ( 'Table 2'[Date], "mmmm" ) = _selectmonth ),
        MONTH ( 'Table 2'[Date] )
    )
RETURN
    SWITCH (
        TRUE (),
        HASONEVALUE ( 'Table 2'[Date].[Year] )
            && HASONEVALUE ( 'Table 2'[Date].[Month] )
            && HASONEVALUE ( 'Table 2'[Date].[Day] ),
            COUNTX (
                FILTER (
                    ALL ( 'Table' ),
                    'Table'[Process Date] <= DATE ( _selectyear, _selectnumber, _selectday )
                ),
                [Opportunity]
            ),
        HASONEVALUE ( 'Table 2'[Date].[Year] )
            && HASONEVALUE ( 'Table 2'[Date].[Month] ),
            COUNTX (
                FILTER (
                    ALL ( 'Table' ),
                    'Table'[Process Date] <= DATE ( _selectyear, _selectnumber, 1 )
                ),
                [Opportunity]
            ),
        HASONEVALUE ( 'Table 2'[Date].[Year] ),
            COUNTX (
                FILTER ( ALL ( 'Table' ), YEAR ( 'Table'[Process Date] ) <= _selectyear ),
                [Opportunity]
            ),
        0
    )
Count Close Date =
VAR _selectyear =
    SELECTEDVALUE ( 'Table 2'[Date].[Year] )
VAR _selectmonth =
    SELECTEDVALUE ( 'Table 2'[Date].[Month] )
VAR _selectday =
    SELECTEDVALUE ( 'Table 2'[Date].[Day] )
VAR _selectnumber =
    MAXX (
        FILTER ( ALL ( 'Table 2' ), FORMAT ( 'Table 2'[Date], "mmmm" ) = _selectmonth ),
        MONTH ( 'Table 2'[Date] )
    )
RETURN
    SWITCH (
        TRUE (),
        HASONEVALUE ( 'Table 2'[Date].[Year] )
            && HASONEVALUE ( 'Table 2'[Date].[Month] )
            && HASONEVALUE ( 'Table 2'[Date].[Day] ),
            COUNTX (
                FILTER (
                    ALL ( 'Table' ),
                    'Table'[Close date] > DATE ( _selectyear, _selectnumber, _selectday )
                ),
                [Opportunity]
            ),
        HASONEVALUE ( 'Table 2'[Date].[Year] )
            && HASONEVALUE ( 'Table 2'[Date].[Month] ),
            COUNTX (
                FILTER (
                    ALL ( 'Table' ),
                    'Table'[Close date] > DATE ( _selectyear, _selectnumber, 1 )
                ),
                [Opportunity]
            ),
        HASONEVALUE ( 'Table 2'[Date].[Year] ),
            COUNTX (
                FILTER ( ALL ( 'Table' ), YEAR ( 'Table'[Close date] ) > _selectyear ),
                [Opportunity]
            ),
        0
    )
ratios =
DIVIDE(
    [Count Process Date],[Count Close Date])

2. Result:

vyangliumsft_0-1668393538600.png

 

Best Regards,

Liu Yang

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

amitchandak
Super User
Super User

@Meep , My HR blog can help

https://community.powerbi.com/t5/Community-Blog/HR-Analytics-Active-Employee-Hire-and-Termination-tr...

 

Also with an independent date table, you can have measures like

 

//Date1 is independent Date table
new measure =
var _max = maxx(allselected(Date1),Date1[Date])
return
calculate( sum(Table[Value]), filter('Table', eomonth('Table'[Request date],0)  = eomonth(_max,0) ))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.