Forum Discussion

apollo89's avatar
apollo89
Helper II
6 years ago
Solved

Use DAX Measure as Categories

Consider the following table:

 

NameFieldValue
AABC-10
ADEF15
BABC-20
BDEF25
CABC15
DABC20
DDEF25
EABC-1
EDEF2

 

I am trying to create categories for 'Name' when the aggregate value of each 'Name' is more than 0.05 times the total of all categories. 

 

For example, Total Value of all is 71 and 71 * 0.05 = 3.55.

So when Total Value of each 'Name' is greater than 3.55, mark it as the 'Name' otherwise mark it as 'Others'.

 

End result:

 

NameTotal ValueCategory
A5A
B5B
C15C
D45D
E1Other

 

This category needs to be column as I will need to place it as a Column in visuals.

 

Steps Taken:

 

1) I build a measure to get aggregated values of 'Name' multipled by 0.05

 

Category Measure = CALCULATE([AMount] * 0.05,ALL('Table'[Name]))
 
This needs to ignore any filters for 'Name' but needs to adhere to any other filter/slicer like 'Field'
 
 

2) Trying to create a Column of this:

 

Category = IF([Total Value] > [Category Measure],'Table'[Name],"Others")
 

Which is not correct.

 

Any help will be appreciated.

  • Hi,

    These calculated column formulas work

    Total for Name = =CALCULATE(SUM(Data[Value]),FILTER(data,Data[Name]=EARLIER(Data[Name])))
    Total for all names = SUM(Data[Value])
    Threshold = 0.05*[Total for all names]
    Category = if([Total for name]>[Threshold],Data[Name],"Others")

    Hope this helps.

16 Replies

  • Hi,

    Write these measures

    Total value = SUM(Data[Value])
    Threshold = 0.05*CALCULATE([Total value],ALL(Data[Name]))
    Measure = if(HASONEVALUE(Data[Name]),if([Total value]>=[Threshold],VALUES(Data[Name]),"Others"))

    Hope this helps.

    • apollo89's avatar
      apollo89
      Helper II

      Thanks Ashish.

       

      However I need to be placing 'Measure' as a column or a slicer in my report visuals which is not possible since it's a Measure. Any other suggestions?

      • Ashish_Mathur's avatar
        Ashish_Mathur
        Super User

        Hi,

        These calculated column formulas work

        Total for Name = =CALCULATE(SUM(Data[Value]),FILTER(data,Data[Name]=EARLIER(Data[Name])))
        Total for all names = SUM(Data[Value])
        Threshold = 0.05*[Total for all names]
        Category = if([Total for name]>[Threshold],Data[Name],"Others")

        Hope this helps.

  • apollo89 , Create this one as a new column

    Category column= sumx(Table,Table[Value]) * 0.05

    or

    Category column= sumx(all(Table),Table[Value]) * 0.05

    Then

    Category Column = IF([Total Value] > [Category column],'Table'[Name],"Others")

    • apollo89's avatar
      apollo89
      Helper II

      Thanks Amit.

       

      This was close but due to negative values also present in my dataset, the category columns are incorrect. Please see the revised dataset in my question. Apologies for the inconvenience.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Here you have 2 versions: one uses an absolute calculation and another one that uses a relative calculation. You don't have to create columns in any tables to make it work. All you need is a disconnected table and a few measures. This is a very flexible design that I think you'll appreciate when you see it.

     

    Best

    D

  • barryc's avatar
    barryc
    Regular Visitor

    Is there anyway to get totals by Category (relative or absolute) i.e. not requireing Name to be part of the Table visual?

    For example in Relative method to select Category[Category Name] in the filter and to see 

    "Others, 7"

    in the table view

    I.e. using a measure (that doesn't appear as a data element in the Input table)

    • Ashish_Mathur's avatar
      Ashish_Mathur
      Super User

      Hi,

      Share some data, describe the question and show the expected result.

      • barryc's avatar
        barryc
        Regular Visitor

        https://1drv.ms/u/s!Am26UCUW42k4gd1lNr7zuQ2pCdEBlQ?e=gm0fF8

        basically I want to show summary totals based on the status.

         

        the status is dynamic based on the dates chosen.

         

        so when the dates are set to show a combination of statuses

         

        say 2 on active-full and two on active-partial 

         

        I want to be able to show on a separate cards (or table) the totals for both statuses and have that dynamically change when the dates change.  So if dates change to make all transactions have a status of Future then we should have a total for just that status.

         

        hope I'm making sense (and hope the quickly put together sample helps.