Forum Discussion

piotr_gor's avatar
piotr_gor
Helper II
4 years ago
Solved

Get a text value from table in measure's variable

Hi there,

 

I've got a table with products, its type and price.

Product NameTypePrice
Product 1 Shampoo5
Product 2Soap2
Product 3Gel3
Product 4Shampoo4
Product 5Body Butter6
Product 6Body Butter7

 

Id' like to create a measure that reads every single Type value of each product and if that value is equel to "Shampoo" to multiply its price by 9%. 

 

I wanted to create variables inside a measure to make more readable at least to me 😉 

 

How do I retrieve product's type in variable?

 

So far I've got:

My measure = 
VAR __Type= 'MyTable'[Type] -- this bit does not work
VAR __Price= SUMX( 'MyTable'[Price] )

VAR __Result = IF ( __Type= "Shampoo", __Price* 1.09, 0 )

RETURN
__Result
  • I wrote a post and something struck me. I should have created new column - not measure. It worked 🙂

2 Replies

  • I wrote a post and something struck me. I should have created new column - not measure. It worked 🙂

  • tamerj1's avatar
    tamerj1
    Community Champion

    Hi piotr_gor 

    just wrap it with sumx

    My measure =
    SUMX (
        'MyTable',
        VAR __Type = 'MyTable'[Type]
        VAR __Price = 'MyTable'[Price]
        VAR __Result =
            IF ( __Type = "Shampoo", __Price * 1.09, 0 )
        RETURN
            __Result
    )