Forum Discussion

_96bp's avatar
_96bp
Regular Visitor
2 years ago
Solved

Calculate next highest Part in same Case by Amount

Hi, I have a table 'MP' that stores the following: [ID]: a case ID [MNr]: a material ID [Amount]: the amount of material used Within each case, multiple different materials can be used with va...
  • Sahir_Maharaj's avatar
    2 years ago

    Hello _96bp,

     

    Can you please try this DAX approach:

    TopRelatedMaterial = 
    VAR SelectedMNr = SELECTEDVALUE(MP[MNr]) -- Assuming there's a way to select a single MNr, like a slicer.
    VAR RelatedMaterials = 
        CALCULATETABLE(
            SUMMARIZE(MP, MP[ID], MP[MNr], "TotalAmount", SUM(MP[Amount])),
            NOT(ISBLANK(MP[Amount])),
            MP[MNr] <> SelectedMNr
        )
    VAR SharedCasesWithSelectedMNr = 
        CALCULATETABLE(
            DISTINCT(MP[ID]),
            MP[MNr] = SelectedMNr
        )
    VAR FilteredRelatedMaterials = 
        FILTER(
            RelatedMaterials,
            MP[ID] IN SharedCasesWithSelectedMNr
        )
    VAR SummarizedRelatedMaterials = 
        SUMMARIZE(
            FilteredRelatedMaterials,
            MP[MNr],
            "SumAmount", SUMX(FILTEREDRelatedMaterials, [TotalAmount])
        )
    VAR RankedMaterials = 
        ADDCOLUMNS(
            SummarizedRelatedMaterials,
            "Rank", RANKX(SummarizedRelatedMaterials, [SumAmount],, DESC, Dense)
        )
    RETURN
        MAXX(FILTER(RankedMaterials, [Rank] = 1), MP[MNr])