Forum Discussion

mayurwadhwani's avatar
5 years ago
Solved

DAX Measure for Date Problem

Hello Experts,

I have a table named Members and below is the data:
Members Table

I want to get distinct count of pkey year wise. If a pkey is active from 2019 to 9999 or till 2019 or greater than 2019 then that pkey will be counted for year 2019 (For startDate 2019 we need to consider records having startdate year as 2019 or less than 2019).
Also I have DateDim (created using dax) for year 2018,2019,2020 and 2021. In my model there is no relationship defined between DateDim and Members table.

Also we have Year slicer in report which we want to pull from DateDim and based on the slicer selection grid should change.

Below is the expected output:

Expected Output

Can we achieve this using DAX measure?

 

Any help or suggestion would highly be appreciated.

 

Thanks

  • Anonymous's avatar
    Anonymous
    5 years ago

    Hi mayurwadhwani ,

    I updated the formula in the original sample pbix file, please check whether it is ok.

     

    Measure = 
    VAR _count =
        COUNTROWS ( ALLSELECTED ( 'DateDim'[Date].[Year] ) )
    VAR _count1 =
        CALCULATE ( DISTINCTCOUNT ( 'DateDim'[Date].[Year] ), ALL ( 'DateDim' ) )
    RETURN
        IF (
            _count = _count1,
            CALCULATE ( DISTINCTCOUNT ( 'Members'[pkey] ) ),
            CALCULATE (
                [Total Count distinct pkey],
                FILTER ( ALLSELECTED ( 'DateDim' ), 'DateDim'[Date] = MAX ( 'DateDim'[Date] ) )
            )
        )

     

    Best Regards

8 Replies