Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin 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.
Hi all,
Your help will be good
I am trying to compare data of two weeks week 39,and week 40 , and am trying to do this:
- do a comparison to see which items occured in week 39 and also week 40, and give it a status "carryover " in a a status collumn
- items that occur in week 39 and not in week 40 give it a status "closed"
- Items that occur in week 40 and not in week 39 give it a status "New"
Table2
category | week # | Status |
a | 39 | |
b | 39 | |
d | 39 | |
a | 40 | |
b | 40 | |
d | 40 | |
E | 40 |
"I am a screen reader"
Solved! Go to Solution.
Hi,
Thank you for sharing your problem. I am assuming you want to do it with dax rather than in power query.
Create a calculated column and write this dax.
use the next code
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlTSUTK2VIrViVZKQjBTEEyQAhMDuAIoMwXBdIUyYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [category = _t, #"week #" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"category", type text}, {"week #", Int64.Type}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Status", each [a=Table.SelectRows(Source, (x)=> x[category]=[category])[#"week #"], b= if a={"39"} then "New" else if a={"40"} then "closed" else "carryover "][b])
in
#"Added Custom"
result in
Hi @PB10 ,
You can also try this dax
Status =
VAR Week39 = CALCULATETABLE(VALUES('Table'[category]), 'Table'[week #] = 39)
VAR Week40 = CALCULATETABLE(VALUES('Table'[category]), 'Table'[week #] = 40)
RETURN
SWITCH(
TRUE(),
SELECTEDVALUE('Table'[category]) IN Week39 && SELECTEDVALUE('Table'[category]) IN Week40, "carryover",
SELECTEDVALUE('Table'[category]) IN Week39 && NOT SELECTEDVALUE('Table'[category]) IN Week40, "closed",
SELECTEDVALUE('Table'[category]) IN Week40 && NOT SELECTEDVALUE('Table'[category]) IN Week39, "New",
BLANK()
)
It outputs exactly what you described.
Best regards,
Albert He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
Hi @PB10 ,
You can also try this dax
Status =
VAR Week39 = CALCULATETABLE(VALUES('Table'[category]), 'Table'[week #] = 39)
VAR Week40 = CALCULATETABLE(VALUES('Table'[category]), 'Table'[week #] = 40)
RETURN
SWITCH(
TRUE(),
SELECTEDVALUE('Table'[category]) IN Week39 && SELECTEDVALUE('Table'[category]) IN Week40, "carryover",
SELECTEDVALUE('Table'[category]) IN Week39 && NOT SELECTEDVALUE('Table'[category]) IN Week40, "closed",
SELECTEDVALUE('Table'[category]) IN Week40 && NOT SELECTEDVALUE('Table'[category]) IN Week39, "New",
BLANK()
)
It outputs exactly what you described.
Best regards,
Albert He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
use the next code
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlTSUTK2VIrViVZKQjBTEEyQAhMDuAIoMwXBdIUyYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [category = _t, #"week #" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"category", type text}, {"week #", Int64.Type}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Status", each [a=Table.SelectRows(Source, (x)=> x[category]=[category])[#"week #"], b= if a={"39"} then "New" else if a={"40"} then "closed" else "carryover "][b])
in
#"Added Custom"
result in
Hi,
Thank you for sharing your problem. I am assuming you want to do it with dax rather than in power query.
Create a calculated column and write this dax.
Thanks, I have tried reading on this before but, explanation is with image tables.
I am vision impaired and use a screen reader, so explanations with images not super helpfull
Apologies.
INTERSECT allows you to find commonalities between two sets of data that have the same columns. It will return the rows that match between the two data sets. That would be your "carryover".
EXCEPT can work either way, identifying the items that are no longer there ( "churn" ) when comparing previous to recent data sets, or the items that are "new" when comparing recent to previous data sets.
Your sample data does not include churn items.
Please read about EXCEPT() and INTERSECT(). There is also a pattern article you can follow. https://www.daxpatterns.com/new-and-returning-customers/
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
13 | |
13 | |
11 | |
8 | |
8 |
User | Count |
---|---|
17 | |
10 | |
7 | |
7 | |
7 |