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

A new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.

Reply
Anonymous
Not applicable

Want to create a button in Direct Query Mode that shows Ranges (years, months, days)

Hi everyone,
 
I used the below formula to create a table (which isn't neccesarily required) in Import mode, the need was for a button that shows the Range (years months days) for the period - see below picture.
NULLifier_0-1662734840758.png
Now I have changed the source to Direct Query mode, but I am not able to create a table inorder to use this formula for the button. So instead I'd like to create a measure? so that I can still use it for the button. I'm not sure how to do this.
 
When I drop the below formula into a measure in direct query mode it produces an error:
"The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value."
 
I am guessing that there needs to be a SUMX formula in there? (I'm a beginner so I'm not sure how I'd even write this)
 
Formula:
 
Ranges =
VAR StartDate = MIN ('Run Time'[StartTime])
VAR EndDate = MAX ('Run Time'[EndTime])
RETURN
{
("Number of Years", DATEDIFF(StartDate, EndDate, YEAR)),
("Number of Quarters", DATEDIFF(StartDate, EndDate, QUARTER)),
("Number of Months", DATEDIFF(StartDate, EndDate, MONTH)),
("Number of Days", DATEDIFF(StartDate, EndDate, DAY))
}
//this formula generates totals for Years, Quarters, Months, Days
 
 Thanks in advance for your help 🙂
1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , Try like

 

Ranges =
VAR StartDate = MIN ('Run Time'[StartTime])
VAR EndDate = MAX ('Run Time'[EndTime])
RETURN
ConcatenateX({
("Number of Years", DATEDIFF(StartDate, EndDate, YEAR)),
("Number of Quarters", DATEDIFF(StartDate, EndDate, QUARTER)),
("Number of Months", DATEDIFF(StartDate, EndDate, MONTH)),
("Number of Days", DATEDIFF(StartDate, EndDate, DAY))
}, [Value], ", ")

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@Anonymous , Try like

 

Ranges =
VAR StartDate = MIN ('Run Time'[StartTime])
VAR EndDate = MAX ('Run Time'[EndTime])
RETURN
ConcatenateX({
("Number of Years", DATEDIFF(StartDate, EndDate, YEAR)),
("Number of Quarters", DATEDIFF(StartDate, EndDate, QUARTER)),
("Number of Months", DATEDIFF(StartDate, EndDate, MONTH)),
("Number of Days", DATEDIFF(StartDate, EndDate, DAY))
}, [Value], ", ")

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Thank you for this, [Value] doesnt exist. There instead appears to be two values, [Value1] and [Value2], so I made two seperate measures for each value. It comes out like this:

NULLifier_0-1662972517386.png

I ask how this could be improved at all?

Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.