Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

Display unique items that appeared each year

I am new to DAX and using Power Query & Powerpivot in Excel 2016 to transform and load data to a pivot. I am simply trying to get a list of Unique Characteristics Values (CHAR VAL) and their counts (Sub-Totals) shown for each year. This measure should adjust itself when i add different filters like Country, Char Description etc to Pivot.

 

 

Item Appearance DateItem Appearance Date (Year)CHAR DESCRIPTIONCHAR VALUE
2017-02-072018LSCBBBB
2017-04-192017LSCCCCC
2017-04-192017LCCCCCC
2017-04-192017CCMBBBB
2017-04-192017CLCMBBBB
2017-06-012017LCCCCCC
2017-06-072017LSCAAAA
2017-06-072017CCMDDDD
2017-07-042018CCMGGGG
2017-07-052018CLCMAAAA
2017-07-072018LCCWWWW
2017-07-072018AVMCAAAA
2016-07-172016CLCMEEEE
2016-07-172016LSCFFFF
2016-10-112016CLCMEEEE
2016-10-122016AVMCZZZZ
2017-10-152017LSCAAAA
2017-10-182017LCCHHHH
2017-10-182017CCMBBBB
2018-03-112017CCMBBBB
2018-03-132017LCCYYYY
2018-03-132017CLCMAAAA
2018-04-122018CLCMDDDD
2018-04-132018CCMDDDD
2018-04-172018LCCCCCC
2018-04-172018AVMCCCCC
2018-06-012018LSCRRRR
2018-06-012017LCCWWWW
2018-06-012017CCMXXXX
2018-06-052017CLCMAAAA
2018-06-052017AVMCCCCC
2018-06-122017AVMCBBBB
2018-06-122017LSCHHHH

 

I am trying to answer the following questions:

  1. how many Unique Char Values are present for each Char Description each year?
  2. what are the top 5 or 10 Char Values for each Char Description each year?
  3. If we have 2 years of data, can we compare past year vs previous to determine Emerging or Trending values?
  4. Anything else interesting about this data?

 

Count of CHAR VALCHAR DESC    
Item Appearance Date (Year)CHAR VALAVMCCCMCLCMLCCLSCUniqueCharCounts
2018DDDD 11   
 BBBB    1 
 GGGG 1   1
 WWWW   1  
 RRRR    11
 AAAA1 1   
 CCCC1  1  
2018 Total 222222
2017DDDD 1    
 HHHH   111
 AAAA  2 2 
 WWWW   1  
 YYYY   1 1
 XXXX 1   1
 BBBB131   
 CCCC1  21 
2017 Total 253543
2016FFFF    11
 EEEE  2  1
 ZZZZ1    1
2016 Total 1 2 13

 

 

I have tried following formulae, but not getting the unique list of items and their unique counts in pivot for each year. e.g. like this:

 

DistinctCounts:=DISTINCTCOUNT('Table1'[CHAR VAL]))

UniqueCharCount:=CALCULATE(COUNTROWS(DISTINCT('Table1'[CHAR VAL])),'Table1'[Item Appearance Date (Year)])

 

Can any DAX Experts please help me quickly?

 

  • Zubair_Muhammad's avatar
    Zubair_Muhammad
    7 years ago

    Anonymous

     

    Try this revision

     

    Distinct Count With Totals =
    IF (
        HASONEFILTER ( tblData[Item Appearance Date (Year) 1] )
            && HASONEFILTER ( tblData[CHAR DESCRIPTION] )
            && HASONEFILTER ( [CHAR VALUE] ),
        [DistinctCount],
        SUMX (
            SUMMARIZE (
                tblData,
                [Item Appearance Date (Year) 1],
                [CHAR DESCRIPTION],
                [CHAR VALUE]
            ),
            [DistinctCount]
        )
    )
    

     

16 Replies

    • Anonymous's avatar
      Anonymous
      Not applicable

       

      Thanks Dale ( v-jiascu-msft ), :smileyhappy:

       

      I am working in Excel 2016 Powerpivot and not using Power BI. Instead of concatenating, cant we have the result as shown above, so that i can see which char values were Emerging in a particular year and which were trending from past years? Also, the length due to concatenation is exceeding in some columns and so unpleasant to read.

       

      Also, some of these Unique Char Values seem to be present in previous years also. They should be unique across entire daterange, so that in each year we get to see which are the unique chars that have entered market.

       

      Item Appearance Date (Year)CHAR DESCUniqueCharsDistinctCount
      2018LSDMXXXX | HHHH2
      2017LSDMXXXX | SSSS2
      2016LSDMXXXX1
      Grand Total XXXX | HHHH | SSSS3

       

      e.g. XXXX has appeared in 2016, 2017, 2018. Hope you are getting my point.

      • Anonymous's avatar
        Anonymous
        Not applicable

        Hi Zubair_Muhammad, i have seen some of your replies.  Can you or any DAX Experts please help me with a solution for my problems?