Forum Discussion

curiouspbix0's avatar
curiouspbix0
Helper IV
5 years ago
Solved

Dax Aggregation Issue

 

Hello Daxers,

 

Running into an aggregation here, first table shows raw data, second table is the dax measure which computes correctly when Status column is not used in the table.


Actual is skewed when Status is added to the table, where did this go wrong ?

 

Raw Data

VehicleStatusVehicle Count
BikesRunning10
BikesActive20
BikesOOO8
CarsRunning10
CarsActive23
CarsOOO11
BoatsRunning100
BoatsActive30
BoatsOOO9
OtherRunning2

Actual = COUNTROWS(DISTINCT(TableVehicle[VehicleID]))
,FILTER(ALL(TableVehicle[Status])
,TableVehicle[VehicleStatus]="Running"
|| TableVehicle[VehicleStatus]="Active")
)

Raw Data with DAX

VehicleActual 
Bikes30
Cars33
Boats130
Other2

 

Actual Result Table - Incorrect

VehicleStatusActual
BikesRunning30
BikesActive30
BikesOOO30
CarsRunning33
CarsActive33
CarsOOO33
BoatsRunning130
BoatsActive130
BoatsOOO130
OtherRunning2

 

What DAX for field Status would result in the below table.

 

Expected Result Table - Correct

VehicleStatus Actual
BikesRunning10
BikesActive20
CarsRunning10
CarsActive23
BoatsRunning100
BoatsActive30
OtherRunning2

 

  • Anonymous's avatar
    Anonymous
    5 years ago

    Hi curiouspbix0 ,

    You can create a measure as below:

    Actual =
    CALCULATE (
        SUM ( 'TableVehicle'[Vehicle Count] ),
        FILTER ( 'TableVehicle', 'TableVehicle'[Status] IN { "Running", "Active" } )
    )

    Best Regards

4 Replies

  • curiouspbix0 , remove all and try

     

    Actual = COUNTROWS(DISTINCT(TableVehicle[VehicleID]))
    ,FILTER((TableVehicle)
    ,TableVehicle[VehicleStatus] in{"Running","Active"})
    )

     

    or

    with allselected

     

    Actual = COUNTROWS(DISTINCT(TableVehicle[VehicleID]))
    ,FILTER(allselected(TableVehicle)
    ,TableVehicle[VehicleStatus] in{"Running","Active"})
    )

    • curiouspbix0's avatar
      curiouspbix0
      Helper IV

      ALLSELECTED did not work and cannot remove ALL together on Filter condition. 

       

  • In modeling click Net Table (write a dax expression to create new table) and write summarize DAX as per blow screenshot,

     

     

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi curiouspbix0 ,

    You can create a measure as below:

    Actual =
    CALCULATE (
        SUM ( 'TableVehicle'[Vehicle Count] ),
        FILTER ( 'TableVehicle', 'TableVehicle'[Status] IN { "Running", "Active" } )
    )

    Best Regards