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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! It's time to submit your entry.

January Power BI Update Carousel

Power BI Monthly Update - January 2026

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

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.