Forum Discussion

Snonsup87's avatar
Snonsup87
New Member
5 months ago
Solved

Column

Dear Masters, I need your advice regarding formula below : ADDCOLUMNS( ADDCOLUMNS( SUMMARIZE(     Equipment,Equipment[Shift Date],Equipment[Shift Code],Equipment[ID Operator],Equipment[...
  • Ritaf1983's avatar
    5 months ago

    Hi Snonsup87 

    The issue occurs because ADDCOLUMNS cannot reference "virtual" columns (like Bucket and RunningHrs) within the same step they are created. To fix this, you must nest the functions so the outer layer can see the columns generated by the inner layer.

    Additionally, you should remove the quotation marks from the column names inside the DIVIDE function, as DAX treats quoted text as strings rather than column references.

    Recommended DAX Solution
    קטע קוד
    EVALUATE
    ADDCOLUMNS(
    ADDCOLUMNS(
    SUMMARIZE(
    Equipment,
    Equipment[Shift Date],
    Equipment[Shift Code],
    Equipment[ID Operator],
    Equipment[Operator Name],
    Equipment[Month],
    Equipment[Year]
    ),
    "Bucket",
    VAR ActualMucking =
    CALCULATE(
    SUM(BucketbyOperator[Actual Mucking]),
    FILTER(
    ALL(BucketbyOperator),
    BucketbyOperator[Date] = Equipment[Shift Date] &&
    BucketbyOperator[Shift] = Equipment[Shift Code] &&
    BucketbyOperator[ID Operator] = Equipment[ID Operator]
    )
    )
    RETURN COALESCE(ActualMucking, 0),

    "RunningHrs",
    CALCULATE(
    SUM(Equipment[Duration (Hour)]),
    Equipment[Status] = "Ready"
    )
    ),
    "TPH",
    DIVIDE([Bucket], [RunningHrs], 0)
    )
    Key Improvements:
    Layering: By wrapping the first ADDCOLUMNS in a second one, the TPH calculation now recognizes [Bucket] and [RunningHrs] as valid fields.

    Performance: Using a variable (VAR) for the Bucket calculation prevents the engine from running the same complex filter twice.

    Syntax Correction: Removed the double quotes from DIVIDE("RunningHrs","Bucket") and changed it to DIVIDE([Bucket], [RunningHrs]).

    COALESCE: Replaced the IF(...=BLANK(), 0, ...) logic with COALESCE, which is the standard, high-performance way to handle nulls in DAX.

    If the logic above does not produce the expected results due to specific relationships in your data model, please upload a sample file (Excel or .PBIX) to a cloud drive (Google Drive, OneDrive, etc.) with a clear example of your desired output and share the link here.

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