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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
wildert
Advocate I
Advocate I

Create a measure that gets the value of another measure for a specific row

I have a table thats used for reporting, and it needs to be filterable by date, salesman, etc in PowerBI / Excel

 

 ReportColumnReportValue
 Sales In US$###
 Sales in California$### 
 Sales Order Count ###

 

so I bang up a table with three rows and a calculated measure (quasi-code)

 

ReportValue = switch(ReportValue,"Sales In US",<some calc to get sales only in US>,"Sales In California",<some calc to get sales only in California>,"Sales Order Count",<some calc to get sales order count>)

 

my problem is that I need <some calc..> to not create its own filter context, because then all my slicers in PowerBI/Excel stop working. I really wish I could use some kind of tuple, or cell address, to specify these values, but it seems like my only choice is summarize/calculate/etc. 

 

To put it another way, I keep hitting the problem mentioned here...

 

http://community.powerbi.com/t5/Desktop/how-to-create-table-Summarizecolumns-keep-filter-context/m-p...

 

any ideas?

1 ACCEPTED SOLUTION
danextian
Super User
Super User

Hi  @wildert,

 

Try this:

 

Create a disconnected calculated table in DAX (no relationship with data table)-

 

Table = 
DATATABLE (
    "Report", STRING,
    "Index", INTEGER,
    {
        { "Sales in US", 1 },
        { "Sales in California", 2 },
        { "Sales Order Count", 3 }
    }
)

Then a switching measure

 

 

 

Value =
VAR SelectedMeasure =
    MIN ( 'Table'[Index] )
RETURN
    IF (
        HASONEVALUE ( 'Table'[Report] ),
        SWITCH (
            SelectedMeasure,
            1, FORMAT ( [Sales in US], "$#,#" ),
            2, FORMAT ( [Sales in California], "$#,#" ),
            FORMAT ( [Order Count], "0,0" )
        )
    )

 










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


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

2 REPLIES 2
wildert
Advocate I
Advocate I

I was having problems because I was not using a totally disconnected table, my table was actually connected to the sales table and it was not giving good behavior for the measure. A totally disconnected table behaves correctly.

danextian
Super User
Super User

Hi  @wildert,

 

Try this:

 

Create a disconnected calculated table in DAX (no relationship with data table)-

 

Table = 
DATATABLE (
    "Report", STRING,
    "Index", INTEGER,
    {
        { "Sales in US", 1 },
        { "Sales in California", 2 },
        { "Sales Order Count", 3 }
    }
)

Then a switching measure

 

 

 

Value =
VAR SelectedMeasure =
    MIN ( 'Table'[Index] )
RETURN
    IF (
        HASONEVALUE ( 'Table'[Report] ),
        SWITCH (
            SelectedMeasure,
            1, FORMAT ( [Sales in US], "$#,#" ),
            2, FORMAT ( [Sales in California], "$#,#" ),
            FORMAT ( [Order Count], "0,0" )
        )
    )

 










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


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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