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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Brookied
Helper I
Helper I

Compare difference between two tables.

Hi Experts, 

 I am in need of some dax help in relation to the below.  In short i need to capture where contacts opt 'OUT' of Email/Phone/SMS/Mail  for tracking reasons where they were previosuly optied 'In'. 

 

I have two tables.  1st is a pre loaded static table i import into PowerBI. this is my base level

Pre-Campaign status Table name = Pre Campaign Consents

NameMediumOpted
BrianEmailIn
BrianMailOut
BrianSMSIn
BrianPhoneIn

 

2nd is the live in progress updates to the above. so i need to recird changes. where the 'Opted" value will possibly change  or remain unchanged. 

 

Post Campaign changes  - Table name = Consents

NameMediumOpted
BrianEmailOut
BrianMailOut
BrianSMSIn
BrianPhoneOut

 

The 'Pre Campaign Consents' & 'Consents' tables are realted by Donor ID as a unique Key

 

I want to capture where Brian was opted 'In' for Email and Phone  but has not Opted 'Out'

 

Possible Result visual

NameMediumPre Campaign ValueNew Opted Value
BrianEmailInOut
BrianPhoneInOut

 

I am not interested in where a contact has opted 'IN' to a medium or if remained unchanged i just need to tracked the change where a contact was opted into Email/Phone/SMS/Post and has opted out for any of these mediums. 

 

Can provide any screen shots needed etc.. 

Thanks in advance. 

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

The proper way would be to create a data model with Name and Medium dimension tables that would then control the two fact tables. But a simpler option would be to take advantage of the merging functions in Power Query that allow you to link tables by more than one column.

 

Pre Contents table:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcirKTMxT0lFyzU3MzAHSnnlKsToIYV+IqH9pCYpwsG8wptqAjPy8VKhwLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, Medium = _t, Opted = _t])
in
    Source

 

Contents table:


let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcirKTMxT0lFyzU3MzAHS/qUlSrE6CHFf7MLBvsFA0jMPRTAgIz8vFaY4FgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, Medium = _t, Opted = _t]),
    #"Merged Queries" = Table.NestedJoin(Source, {"Name", "Medium"}, #"Pre Consents", {"Name", "Medium"}, "Pre Consents", JoinKind.LeftOuter),
    #"Expanded Pre Consents" = Table.ExpandTableColumn(#"Merged Queries", "Pre Consents", {"Opted"}, {"Opted.1"}),
    #"Renamed Columns" = Table.RenameColumns(#"Expanded Pre Consents",{{"Opted.1", "Pre"}}),
    #"Added Custom" = Table.AddColumn(#"Renamed Columns", "Concern", each if [Pre]="In" and [Opted] = "Out" then 1 else 0),
    #"Filtered Rows" = Table.SelectRows(#"Added Custom", each ([Concern] = 1))
in
    #"Filtered Rows"

View solution in original post

6 REPLIES 6
Syndicate_Admin
Administrator
Administrator

when are tables with different columns and a column the same as the merge would do?

Anonymous
Not applicable

Hi @Brookied ,

 

If you just want a table visual, you could create a relationship between thest two tables.

4.PNG

Then create a measure as below and add it to visual level filter.

5.PNG

If you want a new table, you could use merge queries feature in Query Editor to create a new table and create a custom colum.

6.PNG

7.PNG

Then filter the custom = 1 and remove the custom column.

8.PNG

9.PNG

 

Best Regards,

Jay

lbendlin
Super User
Super User

You need to do a merge, not an append.  (Bit of an academic discussion as internally Power Query does not care).

 You said your data source is XML  which is a hierarchical data structure. But your screenshots are already flattened out. Please elaborate.

lbendlin
Super User
Super User

The proper way would be to create a data model with Name and Medium dimension tables that would then control the two fact tables. But a simpler option would be to take advantage of the merging functions in Power Query that allow you to link tables by more than one column.

 

Pre Contents table:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcirKTMxT0lFyzU3MzAHSnnlKsToIYV+IqH9pCYpwsG8wptqAjPy8VKhwLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, Medium = _t, Opted = _t])
in
    Source

 

Contents table:


let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcirKTMxT0lFyzU3MzAHS/qUlSrE6CHFf7MLBvsFA0jMPRTAgIz8vFaY4FgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, Medium = _t, Opted = _t]),
    #"Merged Queries" = Table.NestedJoin(Source, {"Name", "Medium"}, #"Pre Consents", {"Name", "Medium"}, "Pre Consents", JoinKind.LeftOuter),
    #"Expanded Pre Consents" = Table.ExpandTableColumn(#"Merged Queries", "Pre Consents", {"Opted"}, {"Opted.1"}),
    #"Renamed Columns" = Table.RenameColumns(#"Expanded Pre Consents",{{"Opted.1", "Pre"}}),
    #"Added Custom" = Table.AddColumn(#"Renamed Columns", "Concern", each if [Pre]="In" and [Opted] = "Out" then 1 else 0),
    #"Filtered Rows" = Table.SelectRows(#"Added Custom", each ([Concern] = 1))
in
    #"Filtered Rows"

Hi Stumbling along here so decided to post the tables to see if that makes things simpler to figure out. 

 

Below is my "Pre-Consent" table

Brookied_0-1614861166182.png

 

Below is the "Consents" table -  these are realted by "Given By"

Brookied_1-1614861326397.png

 

Thinking about it i would like to "Append"  new Consents given to the 'Pre Consents' table in new columns. These would be  Given By, Medium, Opted.   When i do this it just adds new rows and i get a multiplcation of information. What i want  is to add new Columns where the name matches and medium matches with new Opted values. 

 

So the "Pre-Consents" table with be added with the new columns from 'Consents' Table where it pulls in updated preferences. 

 

Brookied_0-1614883898380.png

 

 

The above should allow me to report on where someone was Opted IN  to a Medium but now Opted OUT.

 

Many Thanks

Morning, Many thanks for the above, if my queries is built from XML can the above be added ?   Sorry for stupid question but never attempted this before. 

 

Cheers

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.