Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
Hi comunnity,
I need help with this problem. I have two simple tables.
The first table contains a list of transports from where - to where (columns "C" - "D") on a given day (column „B“).
The second table contains kilometers (column "D") valid in a given period (columns "E" - "F") for a given destination (columns "B" - "C").
Different kilometers on different dates are due to the detour.
I need to upload the correct kilometers for a given date and destination into the first table.
Thank you Ondřej
Solved! Go to Solution.
You can create a calculated column in the first table like
Distance =
SELECTCOLUMNS (
FILTER (
Table2,
Table2[ID] = Table1[ID]
&& Table2[From] = Table1[From]
&& Table2[To] = Table2[To]
&& Table2[Valid From] <= Table1[Date]
&& (
ISBLANK ( Table2[Valid To] )
|| Table2[Valid To] >= Table1[Date]
)
),
"@value", Table2[Distance]
)
Try
Distance =
SELECTCOLUMNS (
TOPN (
1,
FILTER (
Table2,
Table2[ID] = Table1[ID]
&& Table2[From] = Table1[From]
&& Table2[To] = Table2[To]
&& (
( Table2[Valid From] <= Table1[Date]
&& Table2[Valid To] >= Table1[Date] )
|| ( ISBLANK ( Table2[Valid To] ) && ISBLANK ( Table2[Valid From] ) )
)
),
Table2[Value To], DESC
),
"@value", Table2[Distance]
)
Open DAX Query View and run
EVALUATE
GENERATE (
Table1,
FILTER (
Table2,
Table2[ID] = Table1[ID]
&& Table2[From] = Table1[From]
&& Table2[To] = Table2[To]
&& Table2[Valid From] <= Table1[Date]
&& (
ISBLANK ( Table2[Valid To] )
|| Table2[Valid To] >= Table1[Date]
)
)
)
ORDER BY Table1[Delivery]
That will show you for every row in Table1 all the rows which would be returned from Table2. That should help you identify why multiple rows are being returned.
Hi @johnt75,
could i ask you to modify the formula? I had to adjust the logic in Table2 a little.
Newly, the date will not be filled in for standard kilometers in the mileage records (columns "E" and "F").
In the period of non-standard kilometers, the date will be filled in.
Will it be possible to add kilometers according to the date of the transport as follows?:
1. If it is in the date period, the given km is selected.
2. If it is outside the date period, the km without date (standard kilometers) is selected.
Thanks a lot for your help.
Ondřej
Try
Distance =
SELECTCOLUMNS (
TOPN (
1,
FILTER (
Table2,
Table2[ID] = Table1[ID]
&& Table2[From] = Table1[From]
&& Table2[To] = Table2[To]
&& (
( Table2[Valid From] <= Table1[Date]
&& Table2[Valid To] >= Table1[Date] )
|| ( ISBLANK ( Table2[Valid To] ) && ISBLANK ( Table2[Valid From] ) )
)
),
Table2[Value To], DESC
),
"@value", Table2[Distance]
)
Hi @johnt75,
I ran DAX Query View and found that the data is being assigned incorrectly according to the date from table2.
In the common table I see this:
However, this row from table2 should have been used in the given date:
Thank you
Ondřej
Those dates look like they are stored as strings. Use Power Query to turn them into date type.
Thank you 👍, switching the column format to date helped.
Ondřej
You can create a calculated column in the first table like
Distance =
SELECTCOLUMNS (
FILTER (
Table2,
Table2[ID] = Table1[ID]
&& Table2[From] = Table1[From]
&& Table2[To] = Table2[To]
&& Table2[Valid From] <= Table1[Date]
&& (
ISBLANK ( Table2[Valid To] )
|| Table2[Valid To] >= Table1[Date]
)
),
"@value", Table2[Distance]
)
Thank you Johnt75
When I adjust the distance to the destination in a given period, like this:
An error is displayed. If I leave the distances as in the previous case, 20km was incorrectly added everywhere, on some days it should have been 38km.
It tells me that a table containing multiple values was entered but only one value was expected.
But at first glance I don't see that I have any duplication anywhere. The dates in my mileage table don't overlap but follow each other.
Ondřej
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
76 | |
75 | |
54 | |
38 | |
31 |
User | Count |
---|---|
99 | |
56 | |
50 | |
42 | |
40 |