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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Fidzi8
Helper V
Helper V

Inserting the correct value

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

Fidzi8_0-1743417533637.png

 


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.

Fidzi8_1-1743417533637.png



I need to upload the correct kilometers for a given date and destination into the first table.


Thank you Ondřej

2 ACCEPTED SOLUTIONS
johnt75
Super User
Super User

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]
)

View solution in original post

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]
)

View solution in original post

10 REPLIES 10
v-karpurapud
Community Support
Community Support

Hi @Fidzi8 

Could you please confirm if your query have been resolved the solution provided by @johnt75 ? If they have, kindly mark the helpful response and accept it as the solution. This will assist other community members in resolving similar issues more efficiently.

Thank you

johnt75
Super User
Super User

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.

Fidzi8_0-1749033083471.png

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
works exactly as I need it to. Thank you very much. 👏

Ondřej

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:

Fidzi8_0-1743583689720.png

 



However, this row from table2 should have been used in the given date:

Fidzi8_1-1743583689720.png



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 

johnt75
Super User
Super User

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:

Fidzi8_0-1743422497408.png

 




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.

Fidzi8_1-1743422497411.png

 




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

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.