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
Anonymous
Not applicable

Count short/long terms???

Hello, 

I need a DAX Formula that counts only rows from 15 Columns, if there are more than 30 rows with (Text) values with no interruption (long term). Thanks in advance !

 

7 REPLIES 7
v-jingzhang
Community Support
Community Support

Hi @Anonymous 

 

I guess every column represents a car and every row represents a day? Do you want to count days of every rent term for every car?

 

Best Regards,
Community Support Team _ Jing

Anonymous
Not applicable

I want to count only long rent terms (>30 non-empty rows)

Hi @Anonymous 

 

The table structure is not friendly for DAX, so I transform it into below structure in Power Query editor. Download the attachment for details. 

21102902.jpg 

 

Then create two calculated columns with the following DAX expressions

Flag = 
var _value = 'Table'[Value]
var _previousValue = MAXX(FILTER('Table','Table'[Car ID]=EARLIER('Table'[Car ID])&&'Table'[Index]=EARLIER('Table'[Index])-1),'Table'[Value])
return
IF(_value=""||ISBLANK(_value),0,IF(_value=_previousValue,2,1))  // 0->Not rented day, 1->First rented day, 2->Continuous rented day
Term Day = 
var _firstIndex = IF('Table'[Flag]=1,'Table'[Index],IF('Table'[Flag]=2,MAXX(FILTER('Table','Table'[Car ID]=EARLIER('Table'[Car ID])&&'Table'[Flag]=1&&'Table'[Index]<EARLIER('Table'[Index])),'Table'[Index])))
var _lastIndex = IF('Table'[Flag]<>0,'Table'[Index])
return
IF('Table'[Flag]<>0, _lastIndex - _firstIndex + 1)

 

Finally create a measure

Number of Long Terms = COUNTROWS(FILTER('Table','Table'[Term Day]=31))

 

21102903.jpg

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

Samarth_18
Community Champion
Community Champion

Hi @Anonymous ,

 

Could you please explain your question with some example or sample data with expected output?

It would help you get solution for your question more quickly

 

Thanks,

Samarth

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

Anonymous
Not applicable

I have a Table with car models. Some cars belong to the company and some are rented. I need to count the number of days for the rented cars, but I have to differentiate long term rented days from short term rented days. Long term= more than 30 days with no interruption, short term= less than 30 days

Anonymous
Not applicable

moustafa67_0-1634805921266.png

 

Anonymous
Not applicable

@amitchandak maybe you know ?

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.