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
yharfush
Frequent Visitor

New measure with string values from table

Hello,

 

I have a table which contains sales by store and by product type (A or B):

 

STORE_IDPROD_TYPE
STORE_01A
STORE_01B
STORE_02B
STORE_03A
STORE_03B
STORE_04A
STORE_05B

 

I need to create a measure which will tell me if each store sells Only Prod A, Only Prod B or Both (it would look like this):

 

STORE_IDMEASURE
STORE_01BOTH
STORE_01BOTH
STORE_02ONLY B
STORE_03BOTH
STORE_03BOTH
STORE_04ONLY A
STORE_05ONLY B

 

Any help would be greatly appreciated!

1 ACCEPTED SOLUTION
VahidDM
Super User
Super User

Hi @yharfush 

 

Try this code to create your measure:

 

Measure = 
VAR _A =
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[PROD_TYPE] ),
        ALLEXCEPT ( 'Table', 'Table'[STORE_ID] )
    )
RETURN
    IF ( _A = 2, "Both", "Only " & MAX ( 'Table'[PROD_TYPE] ) )

 

output:

VahidDM_0-1651102585229.png

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 

View solution in original post

2 REPLIES 2
VahidDM
Super User
Super User

Hi @yharfush 

 

Try this code to create your measure:

 

Measure = 
VAR _A =
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[PROD_TYPE] ),
        ALLEXCEPT ( 'Table', 'Table'[STORE_ID] )
    )
RETURN
    IF ( _A = 2, "Both", "Only " & MAX ( 'Table'[PROD_TYPE] ) )

 

output:

VahidDM_0-1651102585229.png

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 


Thank you so much! This works perfectly.

If I can ask another thing, how can I add a filter to the table? Because I have two different time periods for my data and I need to show the results of only one period. I tried this but it doesn't seem to be working:

 

Measure = 
VAR _A =
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[PROD_TYPE] ),
        ALLEXCEPT ( 'Table', 'Table'[STORE_ID] ),
        FILTER( 'Table', 'Table'[PERIOD] = "PERIOD1" )
    )
RETURN
    IF ( _A = 2, "BOTH", "ONLY " & MAX ( 'Table'[PROD_TYPE]  ))

 

Thanks again! 🙂

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.