Forum Discussion

Shree_185's avatar
Shree_185
Helper I
3 years ago
Solved

DAX Calculated Column Help

Hi Everyone, 

 

Trying to replicate the below view in one line query (calculated column)

 

Calculate column = Region-wise Distinct Count ID  WHERE Date is not blank OR Date is not equal to 01/01/2000

 

 

Sample data :

To copy-paste sample data in Excel

RegionIDDate
CGCS001934-A-0011/1/2000
CGCS001935-A-0013/29/2021
CGCS002020-A-00210/18/2021
CGCS002027-A-0029/1/2021
CGCS002033-A-0029/21/2021
CGCS002034-A-0021/1/2000
CTXS000709-A-001 
CTXS001129-A-0016/3/2021
CTXS001136-A-0023/9/2022
CTXS001140-A-0016/22/2022
OPWS000761-A-0011/1/2000
OPWS000773-A-001 
OPWS000775-A-0018/17/2021
OPWS000784-A-0018/27/2021
OPWS000830-A-0017/23/2022
  • If you need the visual you posted, it should work. If you need it in a table visual, you need to add an ALLEXCEPT function in the filter expression:

    Count ID ALLEXCEPT =
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[ID] ),
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[Region] ),
            NOT ( ISBLANK ( 'Table'[Date] ) )
                && 'Table'[Date] <> DATE ( 2000, 1, 1 )
        )
    )
    

    I've attached the sample PBIX file

3 Replies

  • PaulDBrown's avatar
    PaulDBrown
    Community Champion

    Try:

    Count ID =
    CALCULATE(DISTINCTCOUNT(Table[ID), FILTER(Table, NOT(ISBLANK(Table[Date])) && Table[Date] <> DATE(2000, 1, 1)))

    • Shree_185's avatar
      Shree_185
      Helper I

      PaulDBrown Thanks for your help. The logic didn't work? or maybe I did some mistake. can you please send me the PBIX file if possible?

      • PaulDBrown's avatar
        PaulDBrown
        Community Champion

        If you need the visual you posted, it should work. If you need it in a table visual, you need to add an ALLEXCEPT function in the filter expression:

        Count ID ALLEXCEPT =
        CALCULATE (
            DISTINCTCOUNT ( 'Table'[ID] ),
            FILTER (
                ALLEXCEPT ( 'Table', 'Table'[Region] ),
                NOT ( ISBLANK ( 'Table'[Date] ) )
                    && 'Table'[Date] <> DATE ( 2000, 1, 1 )
            )
        )
        

        I've attached the sample PBIX file