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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
Funk-E-Guy
Helper II
Helper II

How to concatenate distinct values of a column, which is generated by multiple filters?

I have two relevant tables that I'm working on;

  • Sales History - A table that reports the number of each product sold each day by country
  • Promotions - A table which tracks which dates a promotion is active for any given products, and what type of promotion is active (discount, sale, coupon, etc). It's entirely possible for multiple promotions to be run on a single product on any given day.

My goal is to have a column in my Sales History table, which is a concatenation of all promotion types active for that product on any given day.

 

I still don't have a full understanding about how all of the formulas interact with each other. Below is a mix of pseudocode and my attempt at the actual code.

 

 

 

Active Promotions = 

concatenate:
    calculate(
        DISTINCT('Promotions'[Type]), 
        filter('Promotions', 'Promotions'[ASIN] = earlier([ASIN])), 
        filter('Promotions', 'Promotions'[Country] = earlier([Country])), 
        filter('Promotions', 'Promotions'[Date] = earlier([Date])),
        AllEXCEPT('Promotions','Promotions'[Type],'Promotions'[ASIN],'Promotions'[Country],'Promotions'[Date])
    )

 

 

 

Here's an example of my promotions table:

 

ASINCountryTypeDate
TestASINUSCoupon12/1/2021
TestASINUSCoupon12/2/2021
TestASINUSCoupon12/3/2021
TestASINUSCoupon12/4/2021
TestASINUSLightning Deal12/1/2021

 

And here's an example of my Sales History table, with the desired column added at the end.

 

ASINCountryDateQTYActive Promotions
TestASINUS11/30/2021100 
TestASINUS12/1/2021500Coupon, Lightning Deal
TestASINUS12/2/2021120Coupon
TestASINUS12/3/2021120Coupon
TestASINUS12/4/2021120Coupon
TestASINUS12/5/2021100 
1 ACCEPTED SOLUTION
smpa01
Super User
Super User

@Funk-E-Guy  you can try this

_desired = 
CALCULATE (
    CALCULATE (
        CONCATENATEX ( Promotions, Promotions[Type], ",", Promotions[Type], ASC ),
        TREATAS (
            SUMMARIZE (
                SalesHistory,
                SalesHistory[Country],
                SalesHistory[Date],
                SalesHistory[ASIN]
            ),
            Promotions[Country],
            Promotions[Date],
            Promotions[ASIN]
        )
    )
)

 

smpa01_0-1639420324923.png

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

View solution in original post

7 REPLIES 7
smpa01
Super User
Super User

@Funk-E-Guy  you can try this

_desired = 
CALCULATE (
    CALCULATE (
        CONCATENATEX ( Promotions, Promotions[Type], ",", Promotions[Type], ASC ),
        TREATAS (
            SUMMARIZE (
                SalesHistory,
                SalesHistory[Country],
                SalesHistory[Date],
                SalesHistory[ASIN]
            ),
            Promotions[Country],
            Promotions[Date],
            Promotions[ASIN]
        )
    )
)

 

smpa01_0-1639420324923.png

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

This seems to do the trick!

 

Thanks!

parry2k
Super User
Super User

@Funk-E-Guy add a column using this:

 

Active Promotions = 
VAR __tbl = CALCULATETABLE ( VALUES ('Text'[Type] ), ALLEXCEPT ( 'Text', 'Text'[ASIN],'Text'[Date],'Text'[Country] ) )
RETURN
CONCATENATEX ( __tbl, [Type], "," )

 

Follow us on LinkedIn

 

Learn about conditional formatting at Microsoft Reactor

My latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

smpa01
Super User
Super User

@Funk-E-Guy  can you please try this as a measure

Measure1= --assuming there is no relationship
VAR _country =
    MAX ( 'Sales History'[Country] )
VAR _day =
    MAX ( 'Sales History'[Day] )
VAR _product =
    MAX ( 'Sales History'[Product] )
RETURN
    CONCATENATEX (
        FILTER (
            Promotions,
            Promotions[Country] = _country
                && Promotions[Day] = _day
                && Promotions[Product] = _product
        ),
        Promotions[Type],
        ",",
        Promotions[Type], ASC
    )
---------------------------------------------------------------------------------------------
Measure2= --assuming there is a relationship
VAR _country =
    MAX ( 'Sales History'[Country] )
VAR _day =
    MAX ( 'Sales History'[Day] )
VAR _product =
    MAX ( 'Sales History'[Product] )
RETURN
    CONCATENATEX (
        FILTER (
            ALL(Promotions),
            Promotions[Country] = _country
                && Promotions[Day] = _day
                && Promotions[Product] = _product
        ),
        Promotions[Type],
        ",",
        Promotions[Type], ASC
    )
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

FYI I edited my post to include some sample data and desired output, in case that changes your answer. Is it possible to do this without the use of measures?

parry2k
Super User
Super User

@Funk-E-Guy it will be easier if you provide some sample data and the expected output.

 

Read this post to get your answer quickly.

https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Post edited

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

March2025 Carousel

Fabric Community Update - March 2025

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

Top Kudoed Authors