Forum Discussion
DAX query to compare two columns from different tables
- 8 years ago
OK, I read that 3 times and I'm not following it. Can you explain it a different way? Sorry!
Thanks Greg_Deckler I see that RELATEDTABLE give you the option to reference another table, but how do I refer to tableB.columnB from tableA.columnA?
Here's an example:
Column = IF(RELATED('OtherTable'[ColumnB])=[ColumnA],1,0)You could also possibly use LOOKUPVALUE.
- MattAdams8 years ago
Helper I
thanks..ill head down this path and update back to you accordingly. Thank you sir.
- MattAdams8 years ago
Helper I
Greg_Deckler Greetings sir. I'm a bit stuck (i am in my first 6 months of pbi bare with me). I have two tables, date (first pic) and task tables (2nd pic). I'm trying to determine from the date table if the date range between "opened date" column, and "resolved date" column (2nd pic) on each record falls on on each calendar date, and if so, make a new column have a value of 1, otherwise 0. I know this may be confusing, but I can't seem to figure out what to use. Its ultimate goal is for looking at aging work that's been open, and seeing how many were open at each day in history if that makes sense. If you can give me your ideas, you're an expert. We are stumped at my company. We are going off the calendar_date column in the date table.
- Greg_Deckler8 years ago
Community Champion
This sounds very similar to something I put together for a call center in terms of open tickets at any particular time. If you can paste in some sample data that I can copy and paste I could create the model/measures for you more specifically. Give me a minute though and I'll see if I can mock something up.
- MattAdams8 years ago
Helper I
WIsh I could upload a xls. Here's pasted. First date table, then task:
ROW_WID CALENDAR_DATE CAL_MONTH_NBR CAL_QTR_NBR CAL_WEEK_NBR CAL_YEAR_NBR CAL_DAY_OF_WEEK_NBR CAL_DAY_NM CAL_DAY_OF_MONTH_NBR MONTH_NM MONTH_NM_SHRT QUARTER_NM QUARTER_SHRT_NM YEAR_HH_NM YY-QQ YY-MM MM-MONTH_NM WEEK_STARTING_SUN WEEK_STARTING_MON WEEK_ENDING_FRI WEEK_ENDING_SUN Same Day 1 - 2 Days 2 - 5 Days 5 - 7 Days 7 - 14 Days 14 - 28 Days 28 - 60 Days 60+ Days 7 - 14 Days 2nd 20170101 Sunday, January 1, 2017 1 1 1 2017 1 Sunday 1 January Jan First Quarter Q1 2017-1H 2017-Q1 2017-01 1-January Sunday, January 1, 2017 Monday, January 2, 2017 Friday, January 6, 2017 ######## 8 20170102 Monday, January 2, 2017 1 1 1 2017 2 Monday 2 January Jan First Quarter Q1 2017-1H 2017-Q1 2017-01 1-January Sunday, January 1, 2017 Monday, January 2, 2017 Friday, January 6, 2017 ######## 8 20170103 Tuesday, January 3, 2017 1 1 1 2017 3 Tuesday 3 January Jan First Quarter Q1 2017-1H 2017-Q1 2017-01 1-January Sunday, January 1, 2017 Monday, January 2, 2017 Friday, January 6, 2017 ######## 8 20170104 Wednesday, January 4, 2017 1 1 1 2017 4 Wednesday 4 January Jan First Quarter Q1 2017-1H 2017-Q1 2017-01 1-January Sunday, January 1, 2017 Monday, January 2, 2017 Friday, January 6, 2017 ######## 8 20170105 Thursday, January 5, 2017 1 1 1 2017 5 Thursday 5 January Jan First Quarter Q1 2017-1H 2017-Q1 2017-01 1-January Sunday, January 1, 2017 Monday, January 2, 2017 Friday, January 6, 2017 ######## 9 20170106 Friday, January 6, 2017 1 1 1 2017 6 Friday 6 January Jan First Quarter Q1 2017-1H 2017-Q1 2017-01 1-January Sunday, January 1, 2017 Monday, January 2, 2017 Friday, January 6, 2017 ######## 9 20170107 Saturday, January 7, 2017 1 1 1 2017 7 Saturday 7 January Jan First Quarter Q1 2017-1H 2017-Q1 2017-01 1-January Sunday, January 1, 2017 Monday, January 2, 2017 Friday, January 6, 2017 ######## 9 20170108 Sunday, January 8, 2017 1 1 2 2017 1 Sunday 8 January Jan First Quarter Q1 2017-1H 2017-Q1 2017-01 1-January Sunday, January 8, 2017 Monday, January 9, 2017 Friday, January 13, 2017 ######## 9 20170109 Monday, January 9, 2017 1 1 2 2017 2 Monday 9 January Jan First Quarter Q1 2017-1H 2017-Q1 2017-01 1-January Sunday, January 8, 2017 Monday, January 9, 2017 Friday, January 13, 2017 ######## 9 20170110 Tuesday, January 10, 2017 1 1 2 2017 3 Tuesday 10 January Jan First Quarter Q1 2017-1H 2017-Q1 2017-01 1-January Sunday, January 8, 2017 Monday, January 9, 2017 Friday, January 13, 2017 ######## 9 20170111 Wednesday, January 11, 2017 1 1 2 2017 4 Wednesday 11 January Jan First Quarter Q1 2017-1H 2017-Q1 2017-01 1-January Sunday, January 8, 2017 Monday, January 9, 2017 Friday, January 13, 2017 ######## 9
- Greg_Deckler8 years ago
Community Champion
MattAdams- OK, I created a Calendar table called Calendar like this:
Calendar = CALENDAR(DATE(2018,1,1),DATE(2018,12,31))
Then I created an Enter Data query like this for a table called Issues:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTLUN9Q3MjC0ADONIcxYnWglI7CAEULOFCFnDBYwQ8iZQ+ViAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Issue = _t, #"Issue Start" = _t, #"Issue End" = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Issue", Int64.Type}, {"Issue Start", type date}, {"Issue End", type date}}) in #"Changed Type"Then I could create this column in the Calendar table:
Issues = COUNTX(FILTER(Issues,Issues[Issue Start]<=[Date] && Issues[Issue End]>=[Date]),Issues[Issue])
- MattAdams8 years ago
Helper I
Let me run with this and give it a try! Thanks for everything you do!
- DAXRichArd7 years ago
Resolver I
Thx for the LOOKUPVALUE solution Gregg,
My problem solving methodology is to hack away and solving my problem. Then I troll our Power BI community. Last I'll post a plea for help. In this case I didn't have to post because I found a solution through researching this forum.
THX Again!
RM
- Anonymous6 years agoNot applicable
Hi,
I have a similar question:
I have WeekStart dates in 'Dates' table and another table (Table B) with various random WeekStart dates.
In Table B, if the WeekStart is in Table A, I need to populate 1 in a column, else 0.
Any leads appreciated!
- Ashish_Mathur6 years ago
Super User
Hi,
RELATED(), RELATEDTABLE() or LOOKUPVALUE() should work. To get specific help, share your data in a form that can be pasted in an MS Excel file and show the expected result.
- DAXRichArd6 years ago
Resolver I
LOOKUPVALUE() worked for me. Thx!
- Zuza1 year agoFrequent Visitor
you just saved me a ton of work, ghatgpt suck's!!!!