Forum Discussion
Determining best or worst project
Dear Power BI community,
First of all i want to wish you all the best in 2026 and thank you for possibility attempting to help resolve my issue.
For a dashboard, i am trying to determine the best and worst project in a selected period. The dashboard shows various other data and has everything displayed twice, once to shown on a week level and once on a year level.
The determination of the best / worst project is done with the following dax formula:
Beste Project Nummer =
VAR SelectedDates =
VALUES ( Datum[Datum] )
VAR Projects =
FILTER(
SUMMARIZE(
Opdracht,
Opdracht[DimOpdrachtId],
Opdracht[Projectnummer],
Opdracht[Korte tekst],
Opdracht[Opleveringsdatum],
"BrutomargePct",
CALCULATE(
[Brutomarge %],
TREATAS(
SelectedDates, Opdracht[Opleveringsdatum] ),
USERELATIONSHIP(Opdracht[Opleveringsdatum], Datum[Datum])
),
"Omzet",
CALCULATE(
SUM(Opbrengsten[zBedrag]),
TREATAS( SelectedDates, Opdracht[Opleveringsdatum]
),
USERELATIONSHIP(Opdracht[Opleveringsdatum], Datum[Datum])
)
),
NOT ISBLANK ( Opdracht[Opleveringsdatum] )
&& [Omzet] >= 1000 -- later finetunen
)
VAR Result =
MAXX( TOPN(1, Projects, [BrutomargePct], DESC), Opdracht[Projectnummer] )
RETURN
IF ( ISBLANK ( Result ), "Geen afgesloten projecten", Result )*determination of worst project is the same but uses ASC instead of DESC in the Result Variable.
In this measure, we determine the best project within the selecteddates (according to date filter in the page using the date table) by calculating the gross margin (brutomargePct) in percentage. This comes from the measure [Brutomarge %] which simply divides two other measures, [Brutomarge] (gross margin) and [Project omzet] (project revenue):
Brutomarge % =
DIVIDE(
[Brutomarge],
[Project Omzet]
)Brutomarge =
CALCULATE(
SUM ( Opbrengsten[zBedrag] ) - SUM ( Kosten[zBedrag] )
)Project Omzet =
CALCULATE(
SUM ( Opbrengsten[zBedrag] )
)
The problem i am facing is as follows:
To determine which projects to use in this summary of projects, the project should be ended within the selected week or year. The project end date comes from Opdracht[Opleveringsdatum]. However, on the dashboard the user filters using the date table (Datum[Datum]). The Date table and Opdracht table have a active relationship, but this is connected to another column and can not have a active relationship to the 'Opleveringsdatum' column because it would break many other things.
When i test in a test dashboarding and filter directly with the 'Opleveringsdatum' instead of using the Date table in the slicer, the result and calculations are correct. However when i move it to the live dashboard where it filters using the date table, none of the values are correct anymore. The Project Revenue, The Gross Margin and Gross Margin % are all correct, causing a incorrectly chosing best/worst project. It does mostly display the correct projects however, so almost always are the actual project numbers correct in both cases.
I tried solving this using the USERELATIONSHIP or TREATAS within the measures, but none of this has worked.
I am very curious to hear your thoughts!
Thanks again,
Olivier
The issue was not the ranking logic itself, but how the data was being filtered and grouped.
We removed DimProjectId from the calculation
Even though it is the technical key, all reporting is done on Projectnummer.
Including DimProjectId caused the calculation to run at a lower grain, which resulted in the wrong project being selected.
Once we removed it, the correct project was ranked as best/worst.We fixed the date filtering in the margin measures
The active calendar relationship interfered with filtering by Opdracht[Opleveringsdatum].
We solved this by clearing the calendar filter and explicitly applying the date filter to Opleveringsdatum.
After these changes, the correct best and worst projects are selected, and the result is consistent across weeks and years.
10 Replies
- o0llied2Frequent Visitor
The issue was not the ranking logic itself, but how the data was being filtered and grouped.
We removed DimProjectId from the calculation
Even though it is the technical key, all reporting is done on Projectnummer.
Including DimProjectId caused the calculation to run at a lower grain, which resulted in the wrong project being selected.
Once we removed it, the correct project was ranked as best/worst.We fixed the date filtering in the margin measures
The active calendar relationship interfered with filtering by Opdracht[Opleveringsdatum].
We solved this by clearing the calendar filter and explicitly applying the date filter to Opleveringsdatum.
After these changes, the correct best and worst projects are selected, and the result is consistent across weeks and years.
- AnonymousNot applicable
Hi o0llied2 ,
We really appreciate your efforts and for letting us know the update on the issue. Glad to know the issue has been resolved
Please continue using fabric community forum for your further assistance.
Thank you
- lbendlin
Super User
- define a numerical calculation for the values behind "best" and "worst"
- calculate that value for each project
- find the maximum and minimum value
- identify the projects that match one of the two values (note there can be multiple projects!)
Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
Do not include sensitive information. Do not include anything that is unrelated to the issue or question.
Please show the expected outcome based on the sample data you provided.
Need help uploading data? https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-p/963216
Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523- o0llied2Frequent Visitor
Hello lbendlin ,
thank you for your reply. Please see below some sample data to get started.
Below are the 4 tables you need with the minimum amount of information required to replicate the issue. I have taken 3 random weeks and 3 random projects within these weeks. The projects are found in the table 'Opdracht', their revenue is in table 'Opbrengsten' and their costs are in table 'Kosten'. Besides these three there should also be a seperate Date table, it only needs all the dates in 2025 to work. The Data model is also shown in a screenshot below.
The information in these tables is also enough to copy paste the DAX formulas shared before.
To recreate the issue, simply create a new page and add a table with the following data:
'Opdracht'[Projectnummer] - 'Opdracht'[Opleveringsdatum] - [Project omzet] - [Brutomarge] - [Brutomarge %] - 'Opdracht'[Korte tekst]
Now add a slicer using 'Opdracht'[Opleveringsdatum] and filter on one of the three dates. A screenshot below with an example for you to check if the data is the same:This data is 100% correct.
Now add a new page with the same table, but add a slicer using the Date column in the date table. Now select the same day, for example 15-12-2025 and you will see the results are vastly different. Same projects, but different numbers.
This is exactly the problem i am trying to solve. Thanks again for taking the time for my issue...
Data model:
Table Opdracht:
Projectnummer Opleveringsdatum Boekdatum DimOpdrachtId Korte Tekst 251861 15-12-2025 19-11-2025 1-OP251861.1 Werkplaats alino, CVI Lelystad 252256 15-12-2025 8-12-2025 1-OP252256.1 SAR - Coatingvloer Waalwijk 252200 15-12-2025 19-11-2025 1-OP252200.1 Unit Eindhoven - opslag + serverruimte 251779 8-12-2025 26-9-2025 1-OP251779.1 Marel Poultry BV Boxmeer - proefkeuken 252187 8-12-2025 17-11-2025 1-OP252187.1 Alexander poort Capelle a/d IJssel 250869 8-12-2025 23-10-2025 1-OP250869.1 Sporthal Grote Beek Eindhoven 241914 16-6-2025 6-6-2025 1-OP241914.1 VVE Bellevue buitentrap 242221 16-6-2025 26-5-2025 1-OP242221.1 StayOkey Hostel Eindhoven 230624 16-6-2025 28-5-2025 1-OP230624.1 Kamp Coating, Vianen Table Opbrengsten:
zBedrag DimOpdrachtId Boekdatum 1608 1-OP251861.1 15-12-2025 201,9 1-OP251861.1 15-12-2025 520 1-OP251861.1 15-12-2025 0 1-OP252256.1 15-12-2025 0 1-OP252256.1 15-12-2025 1925 1-OP252256.1 15-12-2025 0 1-OP252200.1 15-12-2025 2100 1-OP252200.1 15-12-2025 4434,66 1-OP251779.1 8-12-2025 1383,47 1-OP251779.1 8-12-2025 9,6 1-OP251779.1 8-12-2025 2770 1-OP251779.1 8-12-2025 4794 1-OP252187.1 8-12-2025 14100 1-OP252187.1 26-11-2025 11844 1-OP252187.1 1-12-2025 2829,5 1-OP252187.1 8-12-2025 4202,73 1-OP250869.1 8-12-2025 152,08 1-OP250869.1 8-12-2025 € 4.333,00 1-OP241914.1 19-6-2025 € 10.224,93 1-OP242221.1 16-6-2025 € 4.460,50 1-OP230624.1 16-6-2025 Table kosten:
DimOpdrachtId Boekdatum zBedrag 1-OP252256.1 12-12-2025 00:00 569,72 1-OP252256.1 11-12-2025 00:00 1263,35 1-OP252256.1 15-12-2025 00:00 -402,92 1-OP252200.1 30-12-2025 00:00 152,8 1-OP252200.1 12-12-2025 00:00 20 1-OP252200.1 11-12-2025 00:00 20 1-OP252200.1 10-12-2025 00:00 20 1-OP252200.1 9-12-2025 00:00 20 1-OP252200.1 15-12-2025 00:00 1120 1-OP252200.1 8-12-2025 00:00 313,56 1-OP252200.1 23-12-2025 00:00 128,81 1-OP251779.1 1-12-2025 00:00 529,01 1-OP251779.1 3-12-2025 00:00 388,98 1-OP251779.1 5-12-2025 00:00 862,57 1-OP251779.1 4-12-2025 00:00 395,07 1-OP251779.1 25-11-2025 00:00 2308,64 1-OP251779.1 8-12-2025 00:00 -1509,49 1-OP252187.1 19-11-2025 00:00 20 1-OP252187.1 20-11-2025 00:00 1148,93 1-OP252187.1 5-12-2025 00:00 93,5 1-OP252187.1 26-11-2025 00:00 1527,68 1-OP252187.1 24-11-2025 00:00 886,33 1-OP252187.1 27-11-2025 00:00 1408,94 1-OP252187.1 25-11-2025 00:00 3103,47 1-OP252187.1 21-11-2025 00:00 4047,8 1-OP252187.1 18-11-2025 00:00 312,3 1-OP252187.1 4-12-2025 00:00 0 1-OP252187.1 17-11-2025 00:00 2706,9 1-OP252187.1 3-12-2025 00:00 0 1-OP252187.1 2-12-2025 00:00 742,18 1-OP252187.1 17-12-2025 00:00 450 1-OP252187.1 1-12-2025 00:00 2262,51 1-OP252187.1 28-11-2025 00:00 450 1-OP252187.1 9-12-2025 00:00 2500 1-OP252187.1 14-11-2025 00:00 2704,85 1-OP252187.1 8-12-2025 00:00 -1460,03 1-OP252187.1 22-11-2025 00:00 -386,2 1-OP252187.1 23-12-2025 00:00 3250 1-OP250869.1 5-12-2025 00:00 20 1-OP250869.1 12-11-2025 00:00 79,82 1-OP250869.1 2-12-2025 00:00 0 1-OP250869.1 1-12-2025 00:00 110,12 1-OP250869.1 6-12-2025 00:00 0 1-OP250869.1 4-12-2025 00:00 1850 1-OP250869.1 8-12-2025 00:00 280 1-OP250869.1 10-11-2025 00:00 471,15 1-OP250869.1 1-10-2025 00:00 23,74 1-OP250869.1 17-11-2025 00:00 1008,85 1-OP241914.1 10-6-2025 00:00 2057,49 1-OP241914.1 11-6-2025 00:00 -599,5 1-OP241914.1 16-6-2025 00:00 960 1-OP241914.1 12-6-2025 00:00 -632,72 1-OP242221.1 29-5-2025 00:00 40 1-OP242221.1 30-5-2025 00:00 20 1-OP242221.1 2-6-2025 00:00 1629,52 1-OP242221.1 3-6-2025 00:00 10 1-OP242221.1 31-5-2025 00:00 51,36 1-OP242221.1 1-6-2025 00:00 43,8 1-OP242221.1 9-6-2025 00:00 360 1-OP242221.1 27-5-2025 00:00 1499,91 1-OP242221.1 28-5-2025 00:00 2075,9 1-OP242221.1 10-6-2025 00:00 -368,9 1-OP242221.1 5-6-2025 00:00 -379,72 1-OP230624.1 30-5-2025 00:00 931,67 1-OP230624.1 5-6-2025 00:00 1852,32 - AnonymousNot applicable
Hi o0llied2 ,
Try using this DAX functionBeste Project Nummer2 = VAR SelectedDates = VALUES ( Datum[Datum] ) VAR Projects = FILTER ( ADDCOLUMNS ( Opdracht, "Omzet", [Project Omzet], "BrutomargePct", [Brutomarge %] ), NOT ISBLANK ( Opdracht[Opleveringsdatum] ) && Opdracht[Opleveringsdatum] IN SelectedDates && [Omzet] >= 1000 ) RETURN IF ( ISEMPTY ( Projects ), "Geen afgesloten projecten", MAXX ( TOPN ( 1, Projects, [BrutomargePct], DESC ), Opdracht[Projectnummer] ) )I hope this information helps. Please do let us know if you have any further queries.
Thank you
- AnonymousNot applicable
- o0llied2Frequent Visitor
Hello,
I received the message and am currently working on providing sample data, expect to come today!
Thank you very much for checking up on this thread 😄
- amitchandak
Super User
o0llied2 , Better use the index function, which allows partition by and order by
example
calculate([Meausre], index(1, allselected(Table[Device], Table[Last Update Date]), orderby(Table[Last Update Date],desc),,partitionBy(Table[Device]) ) )
Power BI Index: Top/Bottom Performer by name and value: https://youtu.be/HPhzzCwe10U