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
Anonymous
Not applicable

Dynamic calculation in text statements

HelHi All,

 

Can you please help me on one more thing I am looking for something like below

a brand sale 98 Percent  from Asia

b brand sales 80 percent from Europe 

Here each text statement has a calculated value like 98 and 80 which are dynamic when we select filters. This we have achieved in tableau. can we achieve this in Power BI

Please let me know.

 

Thanks & Regards,

Kumar.

1 ACCEPTED SOLUTION
nandukrishnavs
Super User
Super User

@Anonymous 

 

You can use selectedvalue() to get the brand or area. https://www.sqlbi.com/articles/using-the-selectedvalue-function-in-dax/

Example

message =
VAR _brand =
    CALCULATE (
        SELECTEDVALUE ( 'Table'[brand] )
    )
VAR _sales = [Sales] //sales measure
VAR _area =
    CALCULATE (
        SELECTEDVALUE ( 'Table'[area] )
    )
VAR _message = _brand & " sale " & _sales & " Percent from " & _area
RETURN
    _message



Did I answer your question? Mark my post as a solution!
Appreciate with a kudos
🙂

 


Regards,
Nandu Krishna

View solution in original post

2 REPLIES 2
v-shex-msft
Community Support
Community Support

Hi @Anonymous,

I think you need to do some transform in query editor side to create calculation columns to extract specific value form your text statement, then you can simply calculate on these new columns.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlRIKkrMS1EoTsxJVbC0UAhILUpOzStRUEgrys9VcCzOTFSK1YlWSkJSVqxgYaBQAFUHVuZaWpRfkKqgFBsLAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Test = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Test", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Merged", each Text.Combine(List.ReplaceMatchingItems(Text.Split ([Test], " "),{{"brand", ""},{"Percent", ""},{"percent", "" },{"sale", ","},{"sales", ","},{"from", "," }}))),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Added Custom", "Merged", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), {"Brand", "Percent", "Region"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Brand", type text}, {"Percent", Int64.Type}, {"Region", type text}})
in
    #"Changed Type1"

 

14.png

Reference link:

Power Query - Replace multiple substrings in one column 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
nandukrishnavs
Super User
Super User

@Anonymous 

 

You can use selectedvalue() to get the brand or area. https://www.sqlbi.com/articles/using-the-selectedvalue-function-in-dax/

Example

message =
VAR _brand =
    CALCULATE (
        SELECTEDVALUE ( 'Table'[brand] )
    )
VAR _sales = [Sales] //sales measure
VAR _area =
    CALCULATE (
        SELECTEDVALUE ( 'Table'[area] )
    )
VAR _message = _brand & " sale " & _sales & " Percent from " & _area
RETURN
    _message



Did I answer your question? Mark my post as a solution!
Appreciate with a kudos
🙂

 


Regards,
Nandu Krishna

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.