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
Jennifer786
Frequent Visitor

Conditional Column: IF Statement with column values embedded in result text

Hi all

 

I've scoured the web but can't find an answer for this. Is anyone able to point me in the right direction?

 

Im trying to create a custom column with the following logic:

 

Table.AddColumn(#"Added Custom1", "Custom", each if

[Opened vs 1st Time Recorded] < 0 then

"The timesheet indicates that work commenced on this matter"&[TimeDate]&"prior to the file opening"&[OpenDate]&"by "&[Opened vs 1st Time Recorded]&". Confirm and flag if needed." else null)

 

ReferenceTimeDateOpenDateOpened vs 1st Time RecordedCustom
123407/03/2017 00:00:0014/03/2019 00:00-52The timesheet indicates that work commenced on this matter [TimeDate] prior to the file opening [OpenDate] by [Opened vs 1st Time Recorded]. Confirm and flag if need.
1 ACCEPTED SOLUTION

@Jennifer786 ,

 

No problem, thought I'd ask 🙂

 

I think the column formula you want is something like this:

if [Opened vs 1st Time Recorded] < 0 then
Text.Combine({"The timesheet indicates... ", Text.From(Date.From([TimeDate])), " prior to...", Text.From(Date.From([OpenDate])), " by ", Text.From([Opened vs 1st Time Recorded]), ". Confirm..."})
else null

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

7 REPLIES 7
BA_Pete
Super User
Super User

Hi @Jennifer786 ,

 

Quick question: have you tried using the Smart Narrative visual? This is exactly what it does using DAX measures.

BA_Pete_0-1644921668179.png

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Thanks Pete! I'm kind of double jobbing here and want to run this query into excel too. The dataset is huge so I'm trying to resolve it on the query side

@Jennifer786 ,

 

No problem, thought I'd ask 🙂

 

I think the column formula you want is something like this:

if [Opened vs 1st Time Recorded] < 0 then
Text.Combine({"The timesheet indicates... ", Text.From(Date.From([TimeDate])), " prior to...", Text.From(Date.From([OpenDate])), " by ", Text.From([Opened vs 1st Time Recorded]), ". Confirm..."})
else null

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Omg thanks Pete that was perfect!

 

So you nested the Text.Combine within the IF statement which is exactly what I wanted! Did you have to use anything to nest the formulas or does Power query just recognise the formula and where it ends with the 'else' in the IF statement?

@Jennifer786 ,

 

Power query IF statements are divided by the keywords 'if'...'then'...['else if']...'else'.

You can put anything in between them (within reason!) and PQ will distinguish the calculation/functional segment from the IF-clause transition.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Hi Pete - related quesion, I want to display a value from another column within the nested text.combine, but Text.From([% Value]) displays the result as a number e.g. 1.5 instead of 150%.

 

Is there a function or formula for this?

 

EDIT: nevermind! Found it by using Number.ToText([% Value], "p")

great - thanks again Pete!

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.

Top Solution Authors