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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
GallopPBI
Helper III
Helper III

Copy Values

Hello Team,

 

I have the following data on my report as a matrix in PBI Desktop

 

IDCodeNameValue1Value2Value3
5670670003Apples   
 578080Apples407839

 

The ID, Code and Name columns are expanded. I have no Values present for the code 670003. How can I write a calculation to copy the value from the other Code 578080 to the first line. 

 

Output :

 

IDCodeNameValue1Value2Value3
5670670003Apples407839
 578080Apples407839

 

Thanks

1 ACCEPTED SOLUTION

Hi, @GallopPBI 

According to your description, I created the following two tables:

vjianpengmsft_0-1727427944014.png

I use the following DAX expression, which mainly uses the lookup value to obtain the code of another table, so that the number of id, code, and name can be matched:

 

Table 2=
VAR _table =
    ADDCOLUMNS (
        ADDCOLUMNS (
            SELECTCOLUMNS ( 'Table', 'Table'[Key], 'Table'[Name], 'Table'[Code] ),
            "Id", LOOKUPVALUE ( 'Table 2 (2)'[Code], 'Table 2 (2)'[ID], 'Table'[Key] )
        ),
        "Value1", [Measure1],
        "Value2", [Measure2],
        "Value3", [Measure3]
    )
RETURN
    ADDCOLUMNS (
        _table,
        "Value1_new",
            VAR _id = [Id]
            RETURN
                IF (
                    ISBLANK ( [Value1] ),
                    FIRSTNONBLANK (
                        SELECTCOLUMNS ( FILTER ( _table, [Id] = _id ), [Value1] ),
                        [Value1]
                    ),
                    [Value1]
                ),
        "Value2_new",
            VAR _id = [Id]
            RETURN
                IF (
                    ISBLANK ( [Value2] ),
                    FIRSTNONBLANK (
                        SELECTCOLUMNS ( FILTER ( _table, [Id] = _id ), [Value2] ),
                        [Value2]
                    ),
                    [Value2]
                ),
        "Value3_new",
            VAR _id = [Id]
            RETURN
                IF (
                    ISBLANK ( [Value3] ),
                    FIRSTNONBLANK (
                        SELECTCOLUMNS ( FILTER ( _table, [Id] = _id ), [Value3] ),
                        [Value3]
                    ),
                    [Value3]
                )
    )

vjianpengmsft_1-1727428281051.png

 

 

I have included the PBIX file used for this tutorial below.

 

 

 

 

 

 

Best Regards

Jianpeng Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

17 REPLIES 17
Kedar_Pande
Super User
Super User

You can write a measure:
Value1_Fill =
IF (
ISBLANK ( MAX(YourTable[Value1]) ),
CALCULATE (
MAX(YourTable[Value1]),
FILTER (
YourTable,
YourTable[Name] = MAX(YourTable[Name]) &&
NOT(ISBLANK(YourTable[Value1]))
)
),
MAX(YourTable[Value1])
)


Similarly write for Value2 and Value3.

If this post helps, please consider Accepting it as the solution to help the other members find it more quickly and  Your Kudos/Likes are much appreciated!

 

Regards,

Kedar Pande

www.linkedin.com/in/kedar-pande





@Kedar_Pande  Thanks I get this error "The MAX function only accepts a column reference as the argument number 1."

Here’s the updated solution using SELECTEDVALUE():

Value1_Fill =
IF (
ISBLANK ( SELECTEDVALUE(YourTable[Value1]) ),
CALCULATE (
MAX(YourTable[Value1]),
FILTER (
YourTable,
YourTable[Name] = SELECTEDVALUE(YourTable[Name]) &&
NOT(ISBLANK(YourTable[Value1]))
)
),
SELECTEDVALUE(YourTable[Value1])
)

@Thanks I get "Parameter not correct type" for the measure. The Measure is calculated by dividing 2 columns.

GallopPBI
Helper III
Helper III

@v-jianpeng-msft THanks

 

I get the below issue

GallopPBI_0-1727257348435.png

 

The Value1 field is a calculated measure where I divide one value by another. Also ID is actually from another table.

 

Can you please advise? Thanks!

 

Hi, @GallopPBI 

If you're a measure, you should create a new calculated table with your measure, using my previous example data, where I used three measures and then used them to construct a calculated table.
On the constructed calculation table, I added the columns you need, which are basically the same as the previous one, and the following is the DAX expression I used:

 

Table 2 =
ADDCOLUMNS (
    ADDCOLUMNS (
        ALL ( 'Table'[Id], 'Table'[Code], 'Table'[Name] ),
        "Value1", [Measure1],
        "Value2", [Measure2],
        "Value3", [Measure3]
    ),
    "Value1_new",
        VAR _id = 'Table'[Id]
        RETURN
            IF (
                ISBLANK ( [Value1] ),
                FIRSTNONBLANKVALUE (
                    SELECTCOLUMNS ( FILTER ( ALL ( 'Table' ), 'Table'[Id] = _id ), 'Table'[Value1] ),
                    MAX ( 'Table'[Value1] )
                ),
                [Value1]
            ),
    "Value2_new",
        VAR _id = 'Table'[Id]
        RETURN
            IF (
                ISBLANK ( [Value2] ),
                FIRSTNONBLANKVALUE (
                    SELECTCOLUMNS ( FILTER ( ALL ( 'Table' ), 'Table'[Id] = _id ), 'Table'[Value2] ),
                    MAX ( 'Table'[Value2] )
                ),
                [Value2]
            ),
    "Value3_new",
        VAR _id = 'Table'[Id]
        RETURN
            IF (
                ISBLANK ( [Value3] ),
                FIRSTNONBLANKVALUE (
                    SELECTCOLUMNS ( FILTER ( ALL ( 'Table' ), 'Table'[Id] = _id ), 'Table'[Value2] ),
                    MAX ( 'Table'[Value2] )
                ),
                [Value3]
            )
)

 

Here's the calculated table generated by this expression:

vjianpengmsft_0-1727314567484.png

I've provided the PBIX file used this time below.

 

 

Best Regards

Jianpeng Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. 

GallopPBI
Helper III
Helper III

@v-jianpeng-msft  Thanks!

 

However, I get the below error

 

GallopPBI_0-1727256022599.png

 

Please note Value 1 is a calculated measure

 

Value1 = DIVIDE(SUM('Sales'[Net_Sales]),SUM('Qty'[Quantity]))
 
Please advise
 
Thanks

 

v-jianpeng-msft
Community Support
Community Support

Thank you @dharmendars007 

Hi, @GallopPBI 

Based on your description, I use the following example data:

vjianpengmsft_0-1727231899872.png

I've created some calculated columns using the following DAX expression:

Column1 = 
VAR _id = 'Table'[Id]
RETURN
IF(
    ISBLANK('Table'[Value1]),
    FIRSTNONBLANKVALUE(SELECTCOLUMNS(FILTER(ALL('Table'),'Table'[Id]=_id),'Table'[Value1]),MAX('Table'[Value1])),
    'Table'[Value1]
)
Column2 = 
VAR _id = 'Table'[Id]
RETURN
IF(
    ISBLANK('Table'[Value2]),
    FIRSTNONBLANKVALUE(SELECTCOLUMNS(FILTER(ALL('Table'),'Table'[Id]=_id),'Table'[Value2]),MAX('Table'[Value2])),
    'Table'[Value2]
)
Column3 = 
VAR _id = 'Table'[Id]
RETURN
IF(
    ISBLANK('Table'[Value3]),
    FIRSTNONBLANKVALUE(SELECTCOLUMNS(FILTER(ALL('Table'),'Table'[Id]=_id),'Table'[Value3]),MAX('Table'[Value3])),
    'Table'[Value3]
)

Here are the results:

vjianpengmsft_1-1727232005452.png

Then use these calculated columns to create a matrix:

vjianpengmsft_2-1727232058308.png

I've uploaded the PBIX file I used this time below.

 

 

Best Regards

Jianpeng Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@v-jianpeng-msft  Thanks, However I am stuck with the below issue

 

GallopPBI_0-1727336162654.png

 

Hi, @GallopPBI 

I update my DAX expression:

Table 2 =
VAR _table =
    ADDCOLUMNS (
        ALL ( 'Table'[Id], 'Table'[Code], 'Table'[Name] ),
        "Value1", [Measure1],
        "Value2", [Measure2],
        "Value3", [Measure3]
    )
RETURN
    ADDCOLUMNS (
        _table,
        "Value1_new",
            VAR _id = 'Table'[Id]
            RETURN
                IF (
                    ISBLANK ( [Value1] ),
                    FIRSTNONBLANK (
                        SELECTCOLUMNS ( FILTER ( _table, 'Table'[Id] = _id ), [Value1] ),
                        [Value1]
                    ),
                    [Value1]
                ),
        "Value2_new",
            VAR _id = 'Table'[Id]
            RETURN
                IF (
                    ISBLANK ( [Value2] ),
                    FIRSTNONBLANK (
                        SELECTCOLUMNS ( FILTER ( _table, 'Table'[Id] = _id ), [Value2] ),
                        [Value2]
                    ),
                    [Value2]
                ),
        "Value3_new",
            VAR _id = 'Table'[Id]
            RETURN
                IF (
                    ISBLANK ( [Value3] ),
                    FIRSTNONBLANK (
                        SELECTCOLUMNS ( FILTER ( _table, 'Table'[Id] = _id ), [Value3] ),
                        [Value3]
                    ),
                    [Value3]
                )
    )

vjianpengmsft_0-1727341811838.png

 

Best Regards

Jianpeng Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@v-jianpeng-msft Thank you it works but I have an inflated number

 

GallopPBI_0-1727342997255.png

 

Left is old column and right is new...also please note the ID and Code come from different tables. 

 

Thanks

Hi, @GallopPBI 

Could you, taking my sample data, describe what your second table looks like? How are they related?

vjianpengmsft_0-1727343401258.png

 

 

Best Regards

Jianpeng Li

 

@v-jianpeng-msft I have created the same table like in your example. The are independent without a join (i.e Table and Table 2). However, in my model the Table is connected to a calendar and also another table based on the ID Primary key. Thanks

Hi, @GallopPBI 

According to your description, I created the following two tables:

vjianpengmsft_0-1727427944014.png

I use the following DAX expression, which mainly uses the lookup value to obtain the code of another table, so that the number of id, code, and name can be matched:

 

Table 2=
VAR _table =
    ADDCOLUMNS (
        ADDCOLUMNS (
            SELECTCOLUMNS ( 'Table', 'Table'[Key], 'Table'[Name], 'Table'[Code] ),
            "Id", LOOKUPVALUE ( 'Table 2 (2)'[Code], 'Table 2 (2)'[ID], 'Table'[Key] )
        ),
        "Value1", [Measure1],
        "Value2", [Measure2],
        "Value3", [Measure3]
    )
RETURN
    ADDCOLUMNS (
        _table,
        "Value1_new",
            VAR _id = [Id]
            RETURN
                IF (
                    ISBLANK ( [Value1] ),
                    FIRSTNONBLANK (
                        SELECTCOLUMNS ( FILTER ( _table, [Id] = _id ), [Value1] ),
                        [Value1]
                    ),
                    [Value1]
                ),
        "Value2_new",
            VAR _id = [Id]
            RETURN
                IF (
                    ISBLANK ( [Value2] ),
                    FIRSTNONBLANK (
                        SELECTCOLUMNS ( FILTER ( _table, [Id] = _id ), [Value2] ),
                        [Value2]
                    ),
                    [Value2]
                ),
        "Value3_new",
            VAR _id = [Id]
            RETURN
                IF (
                    ISBLANK ( [Value3] ),
                    FIRSTNONBLANK (
                        SELECTCOLUMNS ( FILTER ( _table, [Id] = _id ), [Value3] ),
                        [Value3]
                    ),
                    [Value3]
                )
    )

vjianpengmsft_1-1727428281051.png

 

 

I have included the PBIX file used for this tutorial below.

 

 

 

 

 

 

Best Regards

Jianpeng Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

dharmendars007
Super User
Super User

Hello @GallopPBI , 

 

The best way i think of is using fill up option in Power Query so that values which are presnet in below row will get filled up in above row and vice-versa if you are looking for to copy data below..Aprt from this is there conditions in your logic where you want to copy the data.

 

dharmendars007_0-1727191247393.png

 

dharmendars007_1-1727191270966.png

 

If you find this helpful , please mark it as solution which will be helpful for others and Your Kudos/Likes are much appreciated!

 

Thank You

Dharmendar S

LinkedIN 

 

@dharmendars007 Actually fill up or fill down does not add new values for the missing fields. Thanks

@dharmendars007 Thanks I do not want to backfill data in power query but write a measure or calculated column to fill the data in the report. How can this be done?

 

Yes the condition can be if same ID in this case 5670 then fill up data. Something like if Values are blank and ID is same then fill the values based on the existing number like line 2 in this case.

 

Thanks

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!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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