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
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.

@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


@ 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!:
The Definitive Guide to Power Query (M)

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
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.