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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

Efficient DAX measure - result per row

 Hi,

I am trying to write an efficient DAX measure, but it keeps giving me an error saying there is not enough memory.

I have 4 tables. The following 3 in the image, as well as a dates table, that has a row from the Min date to max date of the vehicle table.

fleet base tables.jpg

I want to create a final table/chart that looks like the following, with the rule

For every single date between the vehicles valid from and to date,

What is its availablity? (if there is a maintenance date, then it is should be flagged as "maintenance", if there was a trip on that date, it should be "used" else "available" )

fleet result.jpg

I also want to create a chart that counts the rows for each date to see how many Cars are being used, not used and maintained.

fleet usage example.jpg

Here is my existing measure which is giving out of memory errors.

Use Measure =
Var var_maintenance = CALCULATE(
FIRSTNONBLANK('Maintenance Table'[Car],1),
FILTER('Maintenance Table',
'Maintenance Table'[Car] = RELATED(Vehicle Table[Car]) &&
'Maintenance Table'[Maintenance Date] = RELATED('Date'[Date])
)
)
return
SWITCH(TRUE(),
var_maintenance <> BLANK(), "Maintenance",
sum(Trips Table[Distance Travelled]) = BLANK(), "Not Used",
"Used"
)

10 REPLIES 10
Ashish_Mathur
Super User
Super User

Hi,

Share those 3 tables in a format that can be pasted in an MS Excel workbook.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Thanks @v-alq-msft . I had previously done this using Power Query - expanding the table. 

I was hoping to avoid that, as I end up with an extremely large table.

@Ashish_Mathur , here are the tables

Vehicle

CarFromto
A1/01/202010/01/2020
B5/01/202012/01/2020
C7/01/202014/01/2020

 

Mtc

CarMaint Date
A2/01/2020
A3/01/2020
A5/01/2020
B6/01/2020
C8/01/2020
C

10/01/2020

trips

CarDateDistance
A1/01/202010.1
A8/01/202015
B7/01/202033.5
B8/01/202036.2
B9/01/202012.5
C7/01/202019.8
C9/01/202021.2
C11/01/202012.3
C13/01/202013.5

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Thanks @Ashish_Mathur 

I was hoping to avoid creating an additional table.

I wanted to achieve the outcome with measures

3 measures - 1 each to determine "used" "not used" and "maintenance" in order to create a stacked column chart that shows these 3 counts per day

Hi,

Which additional table have i created.  Unique vehicles and Calendar tables are definitely required.  Only 1 measure has been used.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Hi

@Ashish_Mathur , I am referring to the expansion of the Vehicles table.

 

I have several thousand vehicles, and if I expand that table to have 1 row per date, I end up with a massive table.

I wanted to avoid this massive table, but if this is the only possible way or the best way, then that is the way I will do it.

 

Thanks again

Hi,

That is the only way I am aware of solving the question.  If my previous reply helped, please mark it as Answer.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-alq-msft
Community Support
Community Support

Hi, @Anonymous 

 

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

Calendar(a calculated table):

Calendar = CALENDAR(MIN(Vehicle[From Date]),MAX(Vehicle[To Date]))

 

Table(a calculated table):

Table = 
var tab = 
UNION(
ADDCOLUMNS(
    GENERATESERIES(
        LOOKUPVALUE(Vehicle[From Date],Vehicle[Car],"A"),
        LOOKUPVALUE(Vehicle[To Date],Vehicle[Car],"A"),
        1
    ),
    "Car",
    "A"
),
ADDCOLUMNS(
    GENERATESERIES(
        LOOKUPVALUE(Vehicle[From Date],Vehicle[Car],"B"),
        LOOKUPVALUE(Vehicle[To Date],Vehicle[Car],"B"),
        1
    ),
    "Car",
    "B"
),
ADDCOLUMNS(
    GENERATESERIES(
        LOOKUPVALUE(Vehicle[From Date],Vehicle[Car],"C"),
        LOOKUPVALUE(Vehicle[To Date],Vehicle[Car],"C"),
        1
    ),
    "Car",
    "C"
)
)
var newtab = 
ADDCOLUMNS(
    tab,
    "Usage",
    IF(
        COUNTROWS(
            FILTER(
                Maintenance,
                [Car]=EARLIER([Car])&&
                [Maintenance Date]=EARLIER([Value])
            )
        )>0,
        "Maintenance",
        IF(
            COUNTROWS(
                FILTER(
                    Trips,
                    [Car]=EARLIER([Car])&&
                    [Date]=EARLIER([Value])
                )
            )>0,
            "Used",
            "Available"
        )
    )
)
var t =
ADDCOLUMNS(
    newtab,
    "Distance",
    IF(
        [Usage]="Used",
        LOOKUPVALUE(Trips[Distance Travelled],Trips[Car],[Car],Trips[Date],[Value])
    )
)
return
t

 

There is a relationship between 'Calendar' and 'Table'. You may create a measue as below.

Result = COUNTROWS('Table')

 

Result: 

   Table:
b1.png

 

b2.png

 

 

Best Regards

Allan

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

amitchandak
Super User
Super User

@Anonymous , Create a date table and Car. Refer to file how to create using distinct. If needed

 

The vehicle you do not join with Date. Other two join. Join all three with Car.

Current = CALCULATE(COUNTx(FILTER(Table,Table[From Date]<=max('Date'[Date]) && ( Table[To Date]>max('Date'[Date]))),(Table[Car])))

 

Create dimension - https://www.dropbox.com/s/op9lb78w9utdonz/Distinct%20from%20two%20Tables.pbix?dl=0

 

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.

I have written a measure to count used and count maintenance but I am having trouble writing one to count for each date, if a vehicle is NOT being used.

Here are my measure which are working.

Can you help create one which counts per date how many Cars are not being used (no trip or maintenance for that date on that car)

countmtc =
CALCULATE(COUNTX(
FILTER(Mtc, Mtc[Maint Date] = RELATED('Date'[Date])),Mtc[Maint Date]
))
countused =
CALCULATE(COUNTX(
FILTER(trips, trips[Date] = RELATED('Date'[Date])),trips[Date]
)
)
Here is my model
model.jpg

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 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.

Top Solution Authors