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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
Silvard
Resolver I
Resolver I

Union and iterate

I’m trying to work out how to use an iterator over a dynamic table/column.
 
I have a fields parameter table to select the dimension to use in the visual (this contains 30 dimensions) and just a normal slicer for the measure (hence using selectedvalue).
 
The below is the structure that I’m trying to use, but there seems to be an issue using union as when I remove it and only use one column, I get the row with the maximum value rather than the total maximum value that I otherwise seem to get.
 
The Filter function is working correctly (confirmed in DAX Query) and generates the relevant rows.
 
VAR CombinedTable = FILTER(UNION(
                        SELECTCOLUMNS(                               VALUES('TOPN (Group)'[Group]),"DynamicValue",'TOPN (Group)'[Group],"Name","Group"),
                        SELECTCOLUMNS(                                 VALUES('TOPN (Job Family)'[Job Family]),"DynamicValue",'TOPN (Job Family)'[Job Family],"Name","Job Family")                           
                                ),
                            [Name] = MAX('Dimension'[Dimension Slicer]) 
)

VAR Result = MAXX(CombinedTable,SWITCH(SELECTEDVALUE('Measure Slicer'[Slicer]),
                         "Amount", [Amount],
                         "Net", [Net]
                        )
                    )

Return 
Result
2 REPLIES 2
Sahir_Maharaj
Super User
Super User

Hello @Silvard,

 

Can you please try this updated approach:

VAR CombinedTable = 
    FILTER(
        UNION(
            SELECTCOLUMNS(VALUES('TOPN (Group)'[Group]), "DynamicValue", 'TOPN (Group)'[Group], "Name", "Group"),
            SELECTCOLUMNS(VALUES('TOPN (Job Family)'[Job Family]), "DynamicValue", 'TOPN (Job Family)'[Job Family], "Name", "Job Family")
        ),
        [Name] = SELECTEDVALUE('Dimension'[Dimension Slicer])
    )

VAR Result = 
    MAXX(
        CombinedTable,
        SWITCH(
            TRUE(),
            SELECTEDVALUE('Measure Slicer'[Slicer]) = "Amount", [Amount],
            SELECTEDVALUE('Measure Slicer'[Slicer]) = "Net", [Net]
        )
    )

RETURN 
    Result

Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution? (Yes, its FREE!)
➤ Lets connect on LinkedIn: Join my network of 15K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ About: https://sahirmaharaj.com/about.html
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning

Hi @Sahir_Maharaj 

 

Thank you for assisting. 

This doesn't work unfortunately.

 

The issue doesn't lie in using MAX to get the value selected (I've confirmed this is working), neither is the issue that in my initial post, I had named the job family column as group rather than job family (although you have correctly corrected this- thank you).


I believe the issue lies in the utilisation of Union - if you remove Union and the subsequent below, it correctly iterates over the table but as is, whether using minx or maxx, I get the same result. To me it seems like the row context is missing? I'm fairly new to power bi so still trying to learn.

SELECTCOLUMNS(VALUES('TOPN (Job Family)'[Job Family]), "DynamicValue", 'TOPN (Job Family)'[Job Family], "Name", "Job Family")
        )

 
Essentially, I would like to be able to select any column in my model and apply iteration over that specific column but it's proving very challenging as Iterators and table functions like Addcolumns,selectcolumns don't accept switch or if statements.

 

I would greatly appreciate your continued assistance.

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.