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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
mettecassoe
New Member

calculate on several filters

My data is registrations of trips by several cars over the last 6 months. 

 

I would like to investigate the lenght (km) of each trip to find out how many trips are less than 100 km, between 100 - 200 km and above 200 km.

 

The cars have a GPS tracker installed that registers start adress and start time/date as well as endadress and end time/date, one registration per row. The car only needs to be standing still for a short while for the end time to be registered, therefore a trip can consist of several rows.

 

My columns are as following:

Car - Date - Adress start - Adress end - start time/date - end time/date - km

 

A simple  

Less than 101 km = COUNTROWS(
FILTER(ReportXls; ReportXls[Km] > 100))
 
is not sufficient as it does not take into account that a trip can include several rows.
 

Im thinking I need something like:

Sort on car

Identify a date for that car

Find the earlies time on that date for that car

Identify Adress start

Identify where Adress stop = Adress stop

Calculate total km for rows 

 

Any help with this is very much appreciated! Thanks in advance.

5 REPLIES 5
V-pazhen-msft
Community Support
Community Support

@mettecassoe 

1. You can use the filter panel, just drag the the columns needs to be filtered into the visual filter.

2. For dax you can use And(&&) , Or(||) to add all those filters in the formula something like: calculate(countrows(ReportXls),filter(ReportXls,ReportXls[Km] > 100 && ReportXls[date]< Date(2020,3,1))

 

Paul Zheng
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

@mettecassoe ,You can use && , and, || ,or, to add additional conditions. You can use the slicers to filter on the fly.

Not sure I got it.

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

@amitchandak Thanks for replying!

 

I have tried eg.

Between 101 and 200 km = CALCULATE(
DISTINCTCOUNT(ReportXls[Indeks]);
FILTER(ReportXls;
ReportXls[Km] > 100
&& ReportXls[Km] < 201
))
 
This would work if one row was = one trip, but in some cases several rows = one trip. I can only identify a trip by finding out the earlies start time on a date for a car, identify the start adress and then find end adress = start adress.
A trip can also be over several days, eg if someone drove somewhere and stayed at a hotel and then drove back the next day.

Sample data would be tremendously helpful. Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Thank you Greg, for the link on how to post correct. 

 

Here is my sample data:

 

CarDateAdress startAdress endStart time dateend time datekm
Nissan QuashqaiJan 31 2020Adress1Adress331-01-2020 11:50:1031-01-2020 11:54:201
Nissan QuashqaiFeb 3 2020Adress3Adress103-02-2020 09:51:5103-02-2020 09:55:101
Nissan NoteJan 31 2020Adress4Adress531-01-2020 14:16:4631-01-2020 14:42:357
Nissan NoteJan 31 2020Adress2Adress731-01-2020 10:20:2331-01-2020 10:23:521
Nissan NoteJan 31 2020Adress2Adress431-01-2020 13:24:2931-01-2020 13:48:486
Nissan NoteFeb 5 2020Adress6Adress205-02-2020 11:05:2805-02-2020 11:07:390
Nissan NoteJan 31 2020Adress7Adress231-01-2020 10:50:5031-01-2020 10:52:200
Nissan NoteFeb 5 2020Adress5Adress605-02-2020 10:35:4005-02-2020 10:40:211

 

As you can see the Quashqai left the home adress1 on Jan 31 and did not return until Feb 3 - total trip 2 km

 

The Note left the home adress2 Jan 31, had a small trip of 1 km and then had another trip starting Jan 31 and returned Feb 5, had several stops in between - total trip 14 km

 

Hope this gives more information to help me. 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.