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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
KHorseman
Community Champion
Community Champion

Weird table creation for DAX gurus

I am really beating my head against a wall on this one. Here's the scenario:

 

In this table I have 2 fields. Call them "Interviewer" and "Contractor". Interviewer is a field with user's full names. Contractor...was designed by an idiot. It's a picklist of first names of users, plus one extra name that isn't a user*. Contractor is sometimes blank when Interviewer is not. Interviewer is never blank. When it is not blank, Contractor usually matches the first name of Interviewer, but not always. Sometimes it's a different person's name and sometimes it's that one extra name. It looks something like this:

 

InterviewerContractor
Stephen FryStephen 
Tim McInnernyRik
Rowan AtkinsonRowan 
Stephen FryStephen 
Hugh LaurieHugh 
Rowan AtkinsonRowan 
Tony RobinsonTony 
Tim McInnernyRowan
Tony RobinsonTony 
Tim McInnernyTim 
Hugh Laurie 
Stephen FryStephen 
Hugh LaurieHugh 
Stephen Fry 
Miranda RichardsonMiranda 
Rowan AtkinsonRowan 
Rowan AtkinsonRik
Stephen FryStephen 
Tony RobinsonRowan
Tony RobinsonRik
Rowan Atkinson 
Tim McInnernyTim 
Rowan AtkinsonRowan 
Miranda RichardsonMiranda 
Miranda RichardsonMiranda 
Tony RobinsonTony 
Tim McInnernyRik
Tony RobinsonTony 
Rowan AtkinsonRik
Rowan Atkinson 
Tim McInnernyTim 
Miranda RichardsonMiranda 
Rowan AtkinsonRowan
Rowan AtkinsonRowan 
Miranda RichardsonMiranda 
Hugh LaurieHugh 
Rowan AtkinsonRowan 
Tim McInnernyTim 
Rowan AtkinsonRowan
Tony Robinson 
Tony RobinsonTony 
Tony RobinsonTony 
Tim McInnernyTim 
Tim McInnernyRik
Rowan AtkinsonRowan 
Tim McInnerny 
Rowan AtkinsonRowan 

 

I need to create a second table that gives me all the contractor full names in one column with the matching interviewer first name, plus that one extra name. So the end product would look like:

 

InterviewerContractor
Rowan AtkinsonRowan
Stephen FryStephen
Hugh LaurieHugh
Tony RobinsonTony
Tim McInnernyTim
Miranda RichardsonMiranda
 Rik

 

I can't do this in the query editor for reasons I won't get into. I can't get there with anything as simple as SUMMARIZE because of the missmatch rows and the fact that there is never a row with a blank Contractor and "Rik" under Interviewer. I am at a loss.

 

@OwenAuger @Greg_Deckler @MattAllington@Seth_C_Bauer @Anonymous save me!

 

 

 

*This is a little white lie. There are actually multiple names like this, but to keep my example simple I'm claiming there's just 1. Also the roster of names in both columns is constantly changing so it's not as if I can hard-code some name values into a filter formula.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




3 ACCEPTED SOLUTIONS
Vvelarde
Community Champion
Community Champion

@KHorseman

 

I think i got it.

 

In your main table add 2 columns:

 

Contractor equal to Interviewer =
IF (
    LEFT ( Table1[Interviewer], FIND ( " "; Table1[Interviewer] ) - 1 )
        = Table1[Contractor],
    1,
    0
)
ExistContractorinallIntervierwersColumn =
COUNTROWS (
    FILTER (
        Table1,
        Table1[Contractor equal to Interviewer] <> 0
            && Table1[Contractor] = EARLIER ( Table1[Contractor] )
    )
)

And a New Table:

 

TheTable =
UNION (
    SUMMARIZE (
        FILTER ( Table1, Table1[Contractor equal to Interviewer] = 1 ),
        Table1[Contractor],
        Table1[Interviewer]
    ),
    SUMMARIZE (
        FILTER (
            Table1,
            Table1[Contractor equal to Interviewer] = 0
                && Table1[Contractor] <> BLANK ()
                && Table1[ExistContractorinallIntervierwersColumn] = BLANK ()
        ),
        Table1[Contractor],
        "Interviewer", BLANK ()
    )
)

UnionTable.png

* I just a Fred to testing.




Lima - Peru

View solution in original post

OK I think I've got this figured out now. @Vvelarde I pretty much just compressed your solution into a single godawful table formula. It ain't pretty, but it does the job.

 

UNION(
	SUMMARIZE(
		FILTER(
			ADDCOLUMNS(
				VALUES(TableName[Contractor]),
				"IntvCheck",
				VAR conname = FIRSTNONBLANK(TableName[Contractor], 1)
				RETURN CALCULATE(
					COUNTROWS(
						FILTER(
							ALL(TableName),
							NOT(ISBLANK(TableName[Interviewer])) &&
							LEFT(
								TableName[Interviewer],
								FIND(" ", TableName[Interviewer]) - 1
							) = conname
						)
					)
				),
				"Interviewer",
				BLANK()
			),
			[IntvCheck] = 0 &&
			NOT(ISBLANK(TableName[Contractor]))
		),
		[Interviewer], [Contractor]
	),
	ADDCOLUMNS(
		SUMMARIZE(
			FILTER(
				TableName,
				NOT(ISBLANK(TableName[Interviewer]))
			),
			TableName[Interviewer]
		),
		"Contractor",
		LEFT(
			[Interviewer],
			FIND(" ", [Interviewer]) - 1
		)
	)
)

That might be the most duct-tape DAX formula I've ever seen.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

Hi @KHorseman

 

I was just playing with this and saw your solution earlier 🙂

 

Here is a version I came up with that should follow exactly the same logic, I've just used variables to split up the steps.

 

TableFinal = 

VAR Interviewers_Fullname_Firstname =
// Two-column table with Interviewers Fullname & Firstname ADDCOLUMNS ( EXCEPT ( VALUES ( TableName[Interviewer] ), { BLANK () } ), "Contractor", LEFT ( TableName[Interviewer], FIND ( " ", TableName[Interviewer] ) - 1 ) )
VAR Interviewers_Firstname = // Interviewers Firstname only, used below
SELECTCOLUMNS ( Interviewers_Fullname_Firstname, "Firstname", [Contractor] ) VAR Contractors = // Contractors from second column of original table
EXCEPT ( VALUES ( TableName[Contractor] ), { BLANK () } ) VAR ContractorsWhoArentInterviewers = // Two-column table containing blanks & Contractors who aren't interviewers
GENERATE ( { BLANK () }, EXCEPT ( Contractors, Interviewers_Firstname ) )
RETURN UNION ( Interviewers_Fullname_Firstname, ContractorsWhoArentInterviewers )

 


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

View solution in original post

10 REPLIES 10

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.