Forum Discussion

EricoVincentciu's avatar
2 years ago
Solved

Dax Calculation on power bi

file excel and pbix 

 

hai i wanna calculate total vehicle and total average base on dept like this 

 

 

 

on facility management (FM)

 

i got total average = 

59,11932

 

and total vehicle = 50

 

 

 

on finish good (FG)

 

i got total average = 

76,45089

 

and total vehicle = 28

 

 

but on my power bi, i canot make data like this 

 

 

this is my total vehicle divide by dept

 

 

 

 

 

 

SumDistinctIfDifferent = 
VAR DistinctInternalIDs = 
    VALUES( 'Table 2024-08-06 until 2024-08-27 (2)'[Total Vehicle 2] )
RETURN
    SUMX(
        DistinctInternalIDs,
        CALCULATE(
            DISTINCTCOUNT( 'Table 2024-08-06 until 2024-08-27 (2)'[internal_id]),
            ALLEXCEPT( 'Table 2024-08-06 until 2024-08-27 (2)', 'Table 2024-08-06 until 2024-08-27 (2)'[dept_id] )
        )
    )

 

 

 

 

 

how to calculate total vehicle and total average like my excel ??

 

 

 

 

total vehicle what i made

 

 

Total Vehicle = DISTINCTCOUNT('Table 2024-08-06 until 2024-08-27 (2)'[internal_id])

 

 

 

DB sql source code :

 

select distinct internal_id, type, status, unit, operational_date, time_start, time_finish,  dept_id from vms_vhl_operational where operational_date between '2024-08-06' and '2024-08-27' and unit = 'MAIN'

 

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi EricoVincentciu ,

     

    I think you need summarize data, so I  suggest you to create measures instead of  calculated table.

    Here I have a test in your sample. I create some measures refering to your excel sample.

    Result is as below.

    Calculated Column:

    A_Category = LEFT('Table 2024-08-06 until 2024-08-27 (2)'[dept_id],SEARCH("-",SUBSTITUTE('Table 2024-08-06 until 2024-08-27 (2)'[dept_id]," ","-"))-1)

    Measures:

    A_Sum of Total Jam = CALCULATE(SUM('Table 2024-08-06 until 2024-08-27 (2)'[Total Jam]))
    A_Total Vehicle = 
    DISTINCTCOUNT('Table 2024-08-06 until 2024-08-27 (2)'[internal_id])
    A_range 6 to 27 *24 = (DATEDIFF(DATE(2024,08,06),DATE(2024,08,27),DAY)+1)*24
    A_Result 1 = [A_Sum of Total Jam]/[A_Total Vehicle]/[A_range 6 to 27 *24]
    A_Result1 * 100 = 
    [A_Result 1] * 100

     

    Best Regards,
    Rico Zhou

     

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

     

3 Replies

  • ahadkarimi's avatar
    ahadkarimi
    Icon for Solution Specialist rankSolution Specialist

    Hi EricoVincentciu, If this is the result you intended, please let me know, and I'll share the two DAX codes related to it.

     

    Did I answer your question? If so, please mark my post as the solution! ✔️
    Your Kudos are much appreciated! Proud to be a Solution Supplier!

    • EricoVincentciu's avatar
      EricoVincentciu
      Icon for Helper II rankHelper II

      thank you for your response, total vehicle what u make is correct, but total average it's wrong i think

      • Anonymous's avatar
        Anonymous
        Not applicable

        Hi EricoVincentciu ,

         

        I think you need summarize data, so I  suggest you to create measures instead of  calculated table.

        Here I have a test in your sample. I create some measures refering to your excel sample.

        Result is as below.

        Calculated Column:

        A_Category = LEFT('Table 2024-08-06 until 2024-08-27 (2)'[dept_id],SEARCH("-",SUBSTITUTE('Table 2024-08-06 until 2024-08-27 (2)'[dept_id]," ","-"))-1)

        Measures:

        A_Sum of Total Jam = CALCULATE(SUM('Table 2024-08-06 until 2024-08-27 (2)'[Total Jam]))
        A_Total Vehicle = 
        DISTINCTCOUNT('Table 2024-08-06 until 2024-08-27 (2)'[internal_id])
        A_range 6 to 27 *24 = (DATEDIFF(DATE(2024,08,06),DATE(2024,08,27),DAY)+1)*24
        A_Result 1 = [A_Sum of Total Jam]/[A_Total Vehicle]/[A_range 6 to 27 *24]
        A_Result1 * 100 = 
        [A_Result 1] * 100

         

        Best Regards,
        Rico Zhou

         

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