Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago

Distinctcount with crossfilter issue

Good afternoon,

I have an issue that I can solve.

 

I have this code : 

CALCULATE(COUNTX(FILTER(Base_PBI,Base_PBI[Date1]<=max('new measure'[Date]) && ((Base_PBI[Date2]>DATE(YEAR(TODAY()),month(today()-1),31)) || Base_PBI[Date2]>max('new measure'[Date]))),Base_PBI[Ent]),CROSSFILTER(Base_PBI[Date1],'new measure'[Date],None))

and now I'm trying to count only the distinct value. I tried with this code :

CALCULATE(DistinctCOUNT(Base_PBI[Ent]),FILTER(Base_PBI,Base_PBI[Date1]<=max('new measure'[Date]) && ((Base_PBI[Date2]>DATE(YEAR(TODAY()),month(today()-1),31)) || Base_PBI[Date2]>max('new measure'[Date]))),CROSSFILTER(Base_PBI[Date1],'new measure'[Date],None))

but it doesnt work. Do you know what's wrong with it?

Thank you

4 Replies

  • Anonymous , Try like

    CALCULATE(CALCULATE(DistinctCOUNT(Base_PBI[Ent]),CROSSFILTER(Base_PBI[Date1],'new measure'[Date],None)),FILTER(Base_PBI,Base_PBI[Date1]<=max('new measure'[Date]) && ((Base_PBI[Date2]>DATE(YEAR(TODAY()),month(today()-1),31)) || Base_PBI[Date2]>max('new measure'[Date]))))

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thank you but it doesn't work, I still have the same false number.

      Perhaps is because of the function distinctcount no? What I want is to count all my lines but one time, like if there are three times the same value in the column "ent", I want to count it as 1. Maybe Discountcount count only the value that are unique? It can be?
      Thank you

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hello Anonymous ,

      I tried to share with you my pbix file but it doesn't work. So I'm joining a table with my dates.

      In power BI, I created a new table that provides me all the date between 01/01/2019 and 31/12/2021. And I would like thanks to this table to have the number of ID that have a start date before the date of this new table and a end_date after it. It will be the number of ID available at this date.

      But as I have some similar ID, Hence I only want the count for unique value. That's why I used distinctcount.

      There is an active relation between my table with dates between 2019 and 2021 and the table below by the start_date.

      I tried this code to have the amount of unique ID available to a given date but it doesnt work.

       

      CALCULATE(DistinctCOUNT(Base_PBI[Ent]),FILTER(Base_PBI,Base_PBI[Start_Date]<=max('new measure'[Date]) && ((Base_PBI[End_Date]>DATE(YEAR(TODAY()),month(today()-1),31)) || Base_PBI[End_Date]>max('new measure'[Date]))),CROSSFILTER(Base_PBI[Start_Date],'new measure'[Date],None))

       

       

      table with my ID, start_Date and End_Date

      IDStart_DateEnd_Date
      15501/01/202015/10/2020
      15501/02/202001/01/2058
      15501/05/202101/01/2079
      12330/01/202130/08/2021
      15501/01/202101/10/2021
      254801/01/198830/01/2029
      8901/01/202130/12/2021
      96612/05/201812/05/2019
      8901/01/202015/10/2020
      8901/02/202001/01/2058
      6601/05/202101/01/2079
      6630/01/202130/08/2021
      3201/01/202101/10/2021
      3201/01/198830/01/2029
      6601/01/202130/12/2021
      254812/05/201812/05/2019
      7801/01/202015/10/2020
      545801/02/202001/01/2058
      21101/05/202101/01/2079
      21130/01/202130/08/2021
      366901/01/202101/10/2021
      58701/01/198830/01/2029
      58701/01/202130/12/2021
      58712/05/201812/05/2019
      45601/01/202015/10/2020
      321501/02/202001/01/2058
      8521101/05/202101/01/2079
      5214530/01/202130/08/2021
      69801/01/202101/10/2021
      322101/01/198830/01/2029
      322101/01/202130/12/2021
      322112/05/201812/05/2019

       

       

      I would like to have a report like this (the number of unique ID available are random)

      DatesNumber of unique ID available

      2019

      12
      202015
      202119

       

      Thank you so much for your help!

      Have a nice day!