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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
h_l
Post Patron
Post Patron

Please Help: create Measure to Sum if value contains in another column

Hi there,

 

in my other posts, i think the problem was described in unclear way, so I didn't really get the solution yet.

Here I try to clarify it in a easier way.

Here is the full sample data in PBI file with all columns.

 

In Table1, [ID] stores value, they are repeated some times, by [Week] or [Type]

h_l_0-1622810753286.png

 

the [ID] values contained in [Page] in Table2

h_l_1-1622812094404.png

 

Question:

Is there a way to create Measure, to Sum Impressions for the [ID] where under WK10 if they are contained in [Page]?

E.g. Sum Impression of [Page] contains [ID]=news012808 or news003863 as they are in WK10.

 

PS: here are the other posts

New Measure, search and return

Adding Trend Line, Track the Result by Group

 

Thanks for reading, appreciate in advance for the help and solution you may provide.

H

 

1 ACCEPTED SOLUTION

@h_l I assumed that they would be part of the visual. I don't see any "week" information in your second table, does it exist? If so, you would do something like this:

Measure =
  VAR __ID = MAX('Table1'[ID])
  VAR __Week = MAX('Table1'[Week])
  VAR __Table = FILTER('Table2',SEARCH(__ID,[Page],1,BLANK()) <> BLANK() && 'Table2'[Week] = __Week)
RETURN
  SUMX(__Table,[Impressions])

 

It's the same exact pattern. You use the && for a logical AND in your filter.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

8 REPLIES 8
Greg_Deckler
Super User
Super User

@h_l I think this is a clearer explanation. If I understand this correctly, you would do something like:

Measure =
  VAR __ID = MAX('Table1'[ID])
  VAR __Table = FILTER('Table2',SEARCH(__ID,[Page],1,BLANK()) <> BLANK())
RETURN
  SUMX(__Table,[Impressions])

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Hi @Greg_Deckler ,

 

Thanks for reply.

In the Measure, where to set limit the "WK10"?

In my OP was taking WK10 as example, but I need to create for the rest of weeks, e.g. WK12, WK14. And to add them into a trend line visual by date.

 

After applying your suggested Measure, they are not Sum in "WK" level.

h_l_0-1622816740991.png

 

It would be acceptable either create Measure for every WK one by one, or if there is a way can automatically Sum as "WK" level as well.

 

Thanks again!

H

 

@h_l I assumed that they would be part of the visual. I don't see any "week" information in your second table, does it exist? If so, you would do something like this:

Measure =
  VAR __ID = MAX('Table1'[ID])
  VAR __Week = MAX('Table1'[Week])
  VAR __Table = FILTER('Table2',SEARCH(__ID,[Page],1,BLANK()) <> BLANK() && 'Table2'[Week] = __Week)
RETURN
  SUMX(__Table,[Impressions])

 

It's the same exact pattern. You use the && for a logical AND in your filter.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Hi @Greg_Deckler , I hope you had a good weekend.

 

There is no "Week" info in Table2. But there is Date info. I didn't paste it in OP image.

h_l_0-1623034414304.png

 

On the other hand, the "Week" info shall not be used in Table2, it is used for decide "Which IDs in Table1 are need to be filtered and selected for Sum of lifetime Impression in Table2" (but not only Sum WK10 impression from Table2.

 

For example, if let's say create Meaure for"Wk12", then it is used for filter:

OK, choose the IDs: faq505081, news012808, deals0324 as they are existing in WK12 in Table1, then Sum their lifetime Impression from Table2.

 

Please let me know if there is a change needed in the DAX.

Thanks again for your help.

 

Have a good day.

@h_l You would need to change the part of the FILTER week = week and perhaps use WEEKNUM. WEEKNUM function (DAX) - DAX | Microsoft Docs

 

Hard to really say. Data is in pictures and so hard to mock up. Sorry, having trouble following, can you post sample data as text and expected output?
Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882

Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

 

@Greg_Deckler  Thanks for the kind remind! I've post another clearer one. (before posting another one, I'm not sure why I cannot reply here, always be warned flood post more than 1 time within 3600s)

 

Hi, @h_l 

Glad to hear that you have posted another clearer case, would you like to mark Greg_Deckler’s reply as a solution to close this case if his reply has helped you in some way?

Thanks in advance!

How to Get Your Question Answered Quickly 

 

Best Regards,

Community Support Team _Robert Qin

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thanks for remind, although it's not the exact solution, but does help a lot!

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.