Forum Discussion

Matpbi's avatar
Matpbi
Frequent Visitor
1 year ago
Solved

Split department values in cities

Hi,   How can I split the wages / worked hours of the guarantee-department over the 3 cities? I want to make a measure with the sum of the "wages" for the 3 departments and divide it through the...
  • Anonymous's avatar
    Anonymous
    1 year ago

    Hi,

    Thanks for the solution bhanu_gautam offered and i want to offer some more infomation foe user to refer to.

    hello Matpbi 

    You can create a measure.

    MEASURE =
    //calculate the city counts in each month
    VAR countcity =
        CALCULATE (
            DISTINCTCOUNT ( 'Table'[City] ),
            ALLSELECTED ( 'Table' ),
            'Table'[Month] IN VALUES ( 'Table'[Month] ),
            'Table'[City] <> BLANK ()
        ) 
    //calculate the wages of Guarantee that dispatch to each city
    VAR wages =
        ROUND (
            DIVIDE (
                CALCULATE (
                    SUM ( 'Table'[Wage] ),
                    ALLSELECTED ( 'Table' ),
                    'Table'[Month] IN VALUES ( 'Table'[Month] ),
                    'Table'[Department] = "Guarantee"
                ),
                countcity
            ),
            2
        ) 
    //calculate the hours of Guarantee that dispatch to each city
    VAR hours =
        ROUND (
            DIVIDE (
                CALCULATE (
                    SUM ( 'Table'[Worked hours] ),
                    ALLSELECTED ( 'Table' ),
                    'Table'[Month] IN VALUES ( 'Table'[Month] ),
                    'Table'[Department] = "Guarantee"
                ),
                countcity
            ),
            2
        ) 
    //calculate the count of department of each city in each month
    VAR counts =
        CALCULATE (
            DISTINCTCOUNT ( 'Table'[Department] ),
            ALLSELECTED ( 'Table' ),
            'Table'[Month] IN VALUES ( 'Table'[Month] ),
            'Table'[City] IN VALUES ( 'Table'[City] )
        ) 
    //calculate  the hours of Guarantee that dispatch to each department of each city
    VAR averagehours =
        ROUND ( DIVIDE ( hours, counts ), 2 ) 
    //calculate the sumwages
    VAR sumwages =
        CALCULATE (
            SUM ( 'Table'[Wage] ),
            ALLSELECTED ( 'Table' ),
            'Table'[Month] IN VALUES ( 'Table'[Month] ),
            'Table'[City] IN VALUES ( 'Table'[City] )
        ) + wages 
    //calculate the sumhours of workshop in each city in each month.
    VAR workshophours =
        CALCULATE (
            SUM ( 'Table'[Worked hours] ),
            ALLSELECTED ( 'Table' ),
            'Table'[Month] IN VALUES ( 'Table'[Month] ),
            'Table'[City] IN VALUES ( 'Table'[City] ),
            'Table'[Department] = "workshop"
        ) + averagehours 
    //divide
    RETURN
        IF ( MAX ( 'Table'[City] ) <> BLANK (), DIVIDE ( sumwages, workshophours ) )
    

    Output

     

    Best Regards!

    Yolo Zhu

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.