Forum Discussion

CPIBecklon's avatar
CPIBecklon
Helper I
2 years ago
Solved

Understanding a DAX formula

Please consider the following formula:  Sample% = DIVIDE(COUNT(DateTimeCompleted[ID]), CALCULATE(COUNT(DateTimeCompleted[ID]),ALLSELECTED(DateTimeCompleted)))   So...I guess I don't understand how...
  • AmiraBedh's avatar
    AmiraBedh
    2 years ago

    When you use ALLSELECTED(DateTimeCompleted), it should indeed remove all the filters from the DateTimeCompleted table, but still respect any filters directly applied by the user. So, if you select "Cake" through a slicer or visual,
    the denominator should technically consider both "Cake" and "Candy", since ALLSELECTED would respect the broader context of the table but would retain the direct user selections.

    Whether a column is directly built into Power Query or if it's a calculated column typically does not affect how ALLSELECTED works. Both types of columns are part of the data model once they are loaded into PBI, and DAX treats them the same way.

    However, the specific way the calculated columns are defined might introduce unexpected filter context.
    But, given the formula you've shared, this doesn't seem to be directly influencing the issue you described.


    What I suggest if you want the denominator to explicitly count only "Cake", regardless of your selections, you can modify your code like below :

    Sample% = DIVIDE(
    COUNT(DateTimeCompleted[ID]),
    CALCULATE(
    COUNT(DateTimeCompleted[ID]),
    ALL(DateTimeCompleted),
    DateTimeCompleted[Item] = "Cake"
    )
    )
    
    


    In this version, ALL(DateTimeCompleted) removes all filters from the DateTimeCompleted table.
    After that,you're explicitly setting the filter context to only consider rows where Item is "Cake".