Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Mani1404
Regular Visitor

Need Help on DAX by passing row value and match with column and get respective row value

I have below table A-E & Ref1 & Ref2. Now i will need to calculate the Sum for each row based on column Ref1 & Ref2. it should take the value of Ref1 and match with columns from A-D, suppose D is value of Ref1 & C for ref2 then it should take from column C & D and give Sum of 100 + 300 = 400 in new calculated measure. I cannot hardcode the column names  using Switch in DAX as they are dynamic and can change. 

 

Table1

TableData.PNG

 

Output

Output.PNG

2 REPLIES 2
Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but please check the attached pbix file.

 

expected result CC = 
VAR _a =
    ADDCOLUMNS (
        VALUES ( 'Data'[ID] ),
        "A", "A",
        "@value", CALCULATE ( SUM ( 'Data'[A] ) )
    )
VAR _b =
    ADDCOLUMNS (
        VALUES ( 'Data'[ID] ),
        "A", "B",
        "@value", CALCULATE ( SUM ( 'Data'[B] ) )
    )
VAR _c =
    ADDCOLUMNS (
        VALUES ( 'Data'[ID] ),
        "A", "C",
        "@value", CALCULATE ( SUM ( 'Data'[C] ) )
    )
VAR _d =
    ADDCOLUMNS (
        VALUES ( 'Data'[ID] ),
        "A", "D",
        "@value", CALCULATE ( SUM ( 'Data'[D] ) )
    )
VAR _e =
    ADDCOLUMNS (
        VALUES ( 'Data'[ID] ),
        "A", "E",
        "@value", CALCULATE ( SUM ( 'Data'[E] ) )
    )
VAR _t =
    SELECTCOLUMNS (
        UNION ( _a, _b, _c, _d, _e ),
        "ID", 'Data'[ID],
        "Ref", [A],
        "@value", [@value]
    )
RETURN
    MAXX (
        FILTER (
            ADDCOLUMNS (
                'Data',
                "@sum",
                    SUMX (
                        FILTER (
                            _t,
                            'Data'[ID] = EARLIER ( 'Data'[ID] )
                                && [Ref] = EARLIER ( 'Data'[Ref1] )
                        ),
                        [@value]
                    )
                        + SUMX (
                            FILTER (
                                _t,
                                'Data'[ID] = EARLIER ( 'Data'[ID] )
                                    && [Ref] = EARLIER ( 'Data'[Ref2] )
                            ),
                            [@value]
                        )
            ),
            Data[ID] = EARLIER ( Data[ID] )
        ),
        [@sum]
    )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Thanks for your response. But the Issue is i cannot hardcode my query. it should do sometime like Hlookup funtionalitiy. take value D from ref1 Column and match with Column header A - E, and get D columns's row value. the issue is i cannot hardcode my values becuase column A-E may increase to A-Z...  

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.