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
STIBBS_807
Resolver I
Resolver I

Create a Measure from Direct Query Connection

I am new to Direct Query on data. I would like to create a measure for an item within a folder of the table.

 

Table format:

Case Table

    Item One

    Item Two

    Folder One

        Folder One Item One

        Folder One Item Two

 

The measure that I am trying to create.

ItemLen = len('Case Table'[Folder One Item Two])

This does not work. I tried this next.

ItemLen = len('Case Table''Folder One'[Folder One Item Two])

This does not work.  

ItemLen = len('Case Table','Folder One',[Folder One Item Two])

This does not work.  

ItemLen = len('Case Table'.'Folder One'.[Folder One Item Two])

This does not work.  

 

I need help with writing this measure.  Thank you.

 

1 ACCEPTED SOLUTION

HI @STIBBS_807 ,

 

Folder is just a display view within your CASES table.

I think the problem here is the DAX function that you are using.

 

LEN function returns the length of a text value. Here you are trying to apply it directly on a column which is wrong. This LEN function works on a single text value.

You can read more details about this function here:

https://learn.microsoft.com/en-us/dax/len-function-dax

 

If you want to use this function on a column, you will have to use an agrregation on your column before applying LEN dax function to it.

Something like this below:

 

 

test = LEN(MAX('Countries emissions'[CO2 Emission Type]))

 

 

 

Hope this helps.

 

 

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

View solution in original post

5 REPLIES 5
STIBBS_807
Resolver I
Resolver I

Still could not get this to work.  So lets go to something simpler.  I have a direct query to a cloud based database.  In the one table I have a start date.  I am trying to figure out how many days has elapsed between the start date and today's date.

Here is my calculation:

DaysOpen = CALCULATE(DATEDIFF(MAX(d_case[ADJUSTED_CASE_START_DATE]),today(),day))
This appears to calculate the days correctly.  
STIBBS_807_0-1762984971177.png

But, I would like the Average Days for the Case.  Just one number for all the DaysOpen. So I did this:

AvgDaysOpen = calculate(AVERAGE((DATEDIFF(MAX(d_case[ADJUSTED_CASE_START_DATE]),today(),day))))

I get this error:

The AVERAGE function only accepts a column reference as an argument.

So I tried to use the measure that I created

AvgDaysOpen = calculate(AVERAGE([DaysOpen]))
This also gives me an error.
The AVERAGE function only accepts a column reference as the argument number 1.
 
Do I have to create some kind of array to average the result from the DaysOpen?
Pragati11
Super User
Super User

Hi @STIBBS_807 ,

 

I don't understand th format of your tables. Can you elaborate more?

What do you mean by "measure for an item within a folder of the table"?

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

Here is the table and the folder I am trying to get to:

STIBBS_807_1-1731531872764.png

I want to get the length of the Case Owner Team item to figure out where to truncate the first four characters off the word.

 

So my formula is: right(Case Owner Team, (len(Case Owner Team)-4))

STIBBS_807_0-1731531574074.png

Here is the Data folder in Power BI.  See the folder in the list.

HI @STIBBS_807 ,

 

Folder is just a display view within your CASES table.

I think the problem here is the DAX function that you are using.

 

LEN function returns the length of a text value. Here you are trying to apply it directly on a column which is wrong. This LEN function works on a single text value.

You can read more details about this function here:

https://learn.microsoft.com/en-us/dax/len-function-dax

 

If you want to use this function on a column, you will have to use an agrregation on your column before applying LEN dax function to it.

Something like this below:

 

 

test = LEN(MAX('Countries emissions'[CO2 Emission Type]))

 

 

 

Hope this helps.

 

 

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

Helpful resources

Announcements
December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.