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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
ERAHUMO
Frequent Visitor

Using field parameters in dax measure to calculate topn

I am trying to make this code work but facing some issues. Here Parameter X and Y are field parameters which i am using as a selection criteria. Now, if i remove the variables Value_Parameter & Measure_Parameter  and just put the column name in the VALUES and TotalMarks, it works fine.

 

Not sure why i am unable to use field parameters with this code.

 

 

 

 

 

TopN_Values = 
VAR Value_Parameter = SelectedValue('Parameter X'[Parameter X Fields])
VAR Measure_Parameter = SelectedValue('Parameter Y'[Parameter Y Fields])

VAR Top3Names =
    TOPN(3, 
        ADDCOLUMNS(
            VALUES(Value_Parameter ), 
            "TotalMarks", Measure_Parameter 
        ), 
        [TotalMarks], DESC
    )
RETURN
    CONCATENATEX(Top3Names, Value_Parameter , ", ")

 

 

 

 

 

3 REPLIES 3
ERAHUMO
Frequent Visitor

Thanks @Anonymous for explaining this. How do i change it from scalar to reference? Is there anything that i can do to achieve this?

Anonymous
Not applicable

Hi @ERAHUMO ,

You can try this:

TopN_Values =
VAR Value_Parameter = SELECTEDVALUE('Parameter X'[Parameter X Fields])
VAR Measure_Parameter = SELECTEDVALUE('Parameter Y'[Parameter Y Fields])
VAR Top3Names =
    TOPN(
        3,
        ADDCOLUMNS(
            VALUES(
                SWITCH(
                    TRUE(),
                    Value_Parameter = "ColumnName1", 'Table'[ColumnName1],
                    Value_Parameter = "ColumnName2", 'Table'[ColumnName2],
                    'Table'[DefaultColumn] // Default case
                )
            ),
            "TotalMarks",
            SWITCH(
                TRUE(),
                Measure_Parameter = "MeasureName1", [Measure1],
                Measure_Parameter = "MeasureName2", [Measure2],
                [DefaultMeasure]
            )
        ),
        [TotalMarks], DESC
    )
RETURN
    CONCATENATEX(Top3Names, [Value_Column], ", ")

Best Regards,

Xianda Tang

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

Anonymous
Not applicable

Hi @ERAHUMO ,

From your description, it sounds like you're trying to dynamically select columns based on user selection and then perform operations like TOPN and CONCATENATEX on these dynamically selected columns. The issue arises because SelectedValue returns a scalar value (the name of the column as text), not a column reference that DAX functions like VALUES and ADDCOLUMNS expect.

Best Regards,

Xianda Tang

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

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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