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
Jnwin
Regular Visitor

Return a Value when Column A matches Column B at any Point

Hello - Looking for assistance with desiging a measure. Essentially looking for the previous year value based on 2 IDs from 2 different tables.  If  'Fact Table'[WeekEndIDPY] = 'Date Table'[WeekendID] at any point then return that value.

 

I do have a year filter that I use coming from the date table, but when used I no longer will have any matches since when applied it filters out the WeekEndIDPY that I need to find the matches for:

 

Column 1: WeekEnddID: this is the current Week IDs
Column 2: WeekEndIDPY: This is the previous year Week IDs. 


For Example with the data below where WeekendIDPY = 1830 and WeekendID = 1830 , so the result should be 1 Unit (plus all the other ones that match in that year).

 

Date Table:

WeekEndDIDWeekEndDIDPYYear
183014662020
183714732020
184414802020
185114872020
185814942020
186515012020
187215082020
187915152020
188615222020
189315292020
190015362020
190715432020
191415502020
192115572020
192815642020
193515712020
194215782020
194915852020
195615922020
196315992020
197016062020
197716132020
198416202020
199116272020
199816342020
200516412020
201216482020
201916552020
202616622020
203316692020
204016762020
204716832020
205416902020
206116972020
206817042020
207517112020
208217182020
208917252020
209617322020
210317392020
211017462020
211717532020
212417602020
213117672020
213817742020
214517812020
215217882020
215917952020
216618022020
217318092020
218018162020
218718232020
219218302020
220118372021
220818442021
221518512021
222218582021
222918652021
223618722021
224318792021
225018862021
225718932021
226419002021
227119072021
227819142021
228519212021
229219282021
229919352021
230619422021
231319492021
232019562021
232719632021
233419702021
234119772021
234819842021
235519912021
236219982021
236920052021
237620122021

 

Fact Table:

WeekEndDIDConsumer Units
18301
18372
18443
18514
18585
18656
18727
18798
18869
189310
190011
190712
191413
192114
192815
193516
194217
194918
195619
196320
197021
197722
198423
199124
199825
200526
201227
201928
202629
203330
204031
204732
205433
206134
206835
207536
208237
208938
209639
210340
211041
211742
212443
213144
213845
214546
215247
215948
216649
217350
218051
218752
219253
220154
220855
221556
222257
222958
223659
224360
225061
225762
226463
227164
227865
228566
229267
229968
230669
231370
232071
232772
233473
234174
234875
235576
236277
236978
237679

Thanks in advanced!

6 REPLIES 6
Jnwin
Regular Visitor

I got it to work by using the following formula, but it ignores the relationships with my other tables (product table). I'm assuming because I'm using calculate and filter together:

PY Units =
CALCULATE (
[Consumer Units],
FILTER (
ALL('Measures'),
' Measures'[WeekEndDID] IN VALUES ( Calendar[WeekEndDIDPY] )
)
)
Fowmy
Super User
Super User

@Jnwin 

You can create the following measure and add it in a Table visual and verify:

PY Units = 
CALCULATE(
    SUM(Table1[Consumer Units]),
    FILTER(
        ALL(Table1),
        Table1[WeekEndDID] = SELECTEDVALUE(Table1[WeekEndDIDPY]) &&
        Table1[Year] = SELECTEDVALUE(Table1[Year])-1
    )
)

Fowmy_0-1627207140179.png


Check your Year at data point for  Consumer Unit 53, the year should be 2021 I think
 

 



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Jnwin
Regular Visitor

I forgot to mention that the consumer units is coming from a fact table, and the week end dates are within a date table, they are joined by week end date IDs. Does this change anything? I'm trying to reproduce this in my report and getting blank results. 

@Jnwin 

it should work as long as you have set up the measure correctly and your relationship is valid. Can you please share your measure for me to check.


Also share the model view of your tables

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Jnwin
Regular Visitor

My measure is similiar as yours but I'm struggling with getting the selectedvalue of the year since it's coming from the date table:

 

PY Units =
CALCULATE(
[Consumer Units],
FILTER(
ALL('Measures'),
'Measures'[WeekEndDID] = SELECTEDVALUE(Calendar[WeekEndDIDPY]) &&
Table1[Year] = SELECTEDVALUE(Table1[Year])-1
)
)
 
I'm not sure if
SELECTEDVALUE(OfftakeWeeklyCalendar[WeekEndDIDPY] works here since I'm not actively filtering on weekendidpy, but the year itself. 
AlexisOlson
Super User
Super User

I think you could use LOOKUPVALUE here.

 

You could write a calculated column like this:

LOOKUPVALUE ( Table1[Consumer Units], Table1[WeekEndID], Table1[WeekEndIDPY] )

 

For a measure, it depends on what you're trying to do. If you're trying to look up the value for a single selected value, then it wouldn't be much different.

LookupMeasure =
VAR Selected_PY_ID = SELECTEDVALUE ( Table1[WeekEndIDPY] )
RETURN
    LOOKUPVALUE ( Table1[Consumer Units], Table1[WeekEndID], Selected_PY_ID )

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.