cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
sagdec Regular Visitor
Regular Visitor

Select a column by parameter

Hi everyone,

 

I am new to Power BI and exploring the dashboard. I have created a measure to calculate the cumulative value.

 

Cumulative Freezer=
CALCULATE (
    SUM ( 'Business Plan'[Freezer] ),
    FILTER (
        ALL ( 'Business Plan'[Period] ),
        'Business Plan'[Period] <= MAX ( 'Business Plan'[Period] )
    )
)

 

However, I want to make the chart more dynamic, like through a parameter selection I will get different cumulative value from different column.

 

But it seems that DAX doesn't have a function like "colnames" which allow me to pass dynamtic column to SUM function.

 

Can anyone help me with it? Thank you very much.

1 ACCEPTED SOLUTION

Accepted Solutions
Moderator Eric_Zhang
Moderator

Re: Select a column by parameter


@sagdec wrote:

Thanks for the disconnected slicer information. But I think the main difference is that I hope to filter by columns but the disconnected slicer filters data by rows. Still thanks for your information.


@sagdec

In my opinion, a better practice for your case is to unpivot the columns and slice the unpivoted column.

Capture.PNG

 

If the way in your original post is still preferable, you could try to create measure as

 

Cumulative Freezer =
SWITCH (
    TRUE (),
    HASONEVALUE ( ParameterTable[Parameter] )
        && ISFILTERED ( ParameterTable[Parameter] )
        && LASTNONBLANK ( ParameterTable[Parameter], "" ) = "Freezer", CALCULATE (
        SUM ( 'Business Plan'[Freezer] ),
        FILTER (
            ALL ( 'Business Plan'[Period] ),
            'Business Plan'[Period] <= MAX ( 'Business Plan'[Period] )
        )
    ),
    HASONEVALUE ( ParameterTable[Parameter] )
        && ISFILTERED ( ParameterTable[Parameter] )
        && LASTNONBLANK ( ParameterTable[Parameter], "" ) = "Washing machine", CALCULATE (
        SUM ( 'Business Plan'[Washing machine] ),
        FILTER (
            ALL ( 'Business Plan'[Period] ),
            'Business Plan'[Period] <= MAX ( 'Business Plan'[Period] )
        )
    ),
    0
)

View solution in original post

6 REPLIES 6
Super User IV
Super User IV

Re: Select a column by parameter

Hi @sagdec

 

You cannot pass a column name into a DAX measure as far as I am aware. 

 

You can pass values within a column to a DAX measure though.

 

Do you have an example of what you are trying to achieve?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






Power BI Blog
sagdec Regular Visitor
Regular Visitor

Re: Select a column by parameter

Capture.PNG

 

Here is a sample of my data. So far I created a measure for column "Freezer".

Cumulative Freezer=
CALCULATE (
    SUM ( 'Business Plan'[Freezer] ),
    FILTER (
        ALL ( 'Business Plan'[Period] ),
        'Business Plan'[Period] <= MAX ( 'Business Plan'[Period] )
    )
)

I hope that I can have different measure for different columns using parameter or other method so that I do not need to create new measure for every single column. A sample chart is below:

 

Capture2.PNG

Super User IV
Super User IV

Re: Select a column by parameter

Hi @sagdec

 

It appears that you could use the disconnected slicers option in which you might have to create a few measures, but for the end user they can click on a slicer and it will change dynamically for them?

 

https://www.fourmoo.com/2017/08/08/power-bi-how-disconnected-slicers-can-enrich-transform-your-analy...





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






Power BI Blog
sagdec Regular Visitor
Regular Visitor

Re: Select a column by parameter

Thanks for the disconnected slicer information. But I think the main difference is that I hope to filter by columns but the disconnected slicer filters data by rows. Still thanks for your information.

Moderator Eric_Zhang
Moderator

Re: Select a column by parameter


@sagdec wrote:

Thanks for the disconnected slicer information. But I think the main difference is that I hope to filter by columns but the disconnected slicer filters data by rows. Still thanks for your information.


@sagdec

In my opinion, a better practice for your case is to unpivot the columns and slice the unpivoted column.

Capture.PNG

 

If the way in your original post is still preferable, you could try to create measure as

 

Cumulative Freezer =
SWITCH (
    TRUE (),
    HASONEVALUE ( ParameterTable[Parameter] )
        && ISFILTERED ( ParameterTable[Parameter] )
        && LASTNONBLANK ( ParameterTable[Parameter], "" ) = "Freezer", CALCULATE (
        SUM ( 'Business Plan'[Freezer] ),
        FILTER (
            ALL ( 'Business Plan'[Period] ),
            'Business Plan'[Period] <= MAX ( 'Business Plan'[Period] )
        )
    ),
    HASONEVALUE ( ParameterTable[Parameter] )
        && ISFILTERED ( ParameterTable[Parameter] )
        && LASTNONBLANK ( ParameterTable[Parameter], "" ) = "Washing machine", CALCULATE (
        SUM ( 'Business Plan'[Washing machine] ),
        FILTER (
            ALL ( 'Business Plan'[Period] ),
            'Business Plan'[Period] <= MAX ( 'Business Plan'[Period] )
        )
    ),
    0
)

View solution in original post

sagdec Regular Visitor
Regular Visitor

Re: Select a column by parameter

Thank you! I think unpivot columns are suitable for my case and thank you for the code I will also try!

Helpful resources

Announcements
Exclusive LIVE Community Event #3 – Ask Arun Anything

Exclusive LIVE Community Event #3 – Ask Arun Anything

Join us in the third Triple A event!

Meet the 2020 Season 1 Power BI Super Users!

Meet the 2020 Season 1 Power BI Super Users!

It’s the start of a new Super User season! Learn all about the new Super Users and brand-new tiered recognition system.

January 2020 Community Highlights

January 2020 Community Highlights

Make sure you didn't miss any of the things that happened in the community in January!

Top Solution Authors
Top Kudoed Authors