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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
jeongkim
Post Partisan
Post Partisan

Get single value using VAR from multiple value options

Hi

 

Can anyone help me write a full code?

 

 

Step1. Try to get value from below data source first.

 

Table name: GR - 5G SvC_master ~ 2022 - Previous Backup Data

Column name for value to fetch: GR Date

Column name for key identifier to match : Site

 

jeongkim_0-1736137134689.png

 

Step2. If Step 1 doesn't find any value, then try to get single value from below table which has multiple values so need to get only 1 latest value using Index column(latest= Index bigger number). 

 

Table name: GR - 5G SvC_master since 2023 - Current Monthly Data

Column name for value to fetch: GR Date

Column name for key identifier to match : Site

 

jeongkim_1-1736137174091.png

 

 

Final value destination is below:

(example of code but now error due to my poor coding) 

 

Table name: Distinct - Master Data

Column name for value destination: GR Date

Column name for key identifier to match: Internal Site ID

jeongkim_2-1736137503767.png

 

1 ACCEPTED SOLUTION
v-tangjie-msft
Community Support
Community Support

Hi @jeongkim ,

 

According to your description, here are my steps you can follow as a solution.

(1) This is my test data.  

vtangjiemsft_0-1736215908659.png

vtangjiemsft_1-1736215934639.png

vtangjiemsft_2-1736215957549.png

(2) We can create a calculated column.

GR Date =
VAR _a =
    LOOKUPVALUE (
        'GR - 5G SvC_master ~ 2022 - Previous Backup Data'[GR Date],
        'GR - 5G SvC_master ~ 2022 - Previous Backup Data'[Site], [Internal Site ID]
    )
VAR _max_index =
    CALCULATE (
        MAX ( 'GR - 5G SvC_master since 2023 - Current Monthly Data'[Index] ),
        FILTER (
            'GR - 5G SvC_master since 2023 - Current Monthly Data',
            [Site] = EARLIER ( 'Distinct - Master Data'[Internal Site ID] )
        )
    )
VAR _b =
    CALCULATE (
        MAX ( 'GR - 5G SvC_master since 2023 - Current Monthly Data'[GR Date] ),
        FILTER (
            'GR - 5G SvC_master since 2023 - Current Monthly Data',
            [Site] = EARLIER ( 'Distinct - Master Data'[Internal Site ID] )
                && [Index] = _max_index
        )
    )
RETURN
    IF ( ISBLANK ( _a ), _b, _a )

(3) Then the result is as follows.

vtangjiemsft_3-1736216157328.png

 

Best Regards,

Neeko Tang

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

4 REPLIES 4
v-tangjie-msft
Community Support
Community Support

Hi @jeongkim ,

 

According to your description, here are my steps you can follow as a solution.

(1) This is my test data.  

vtangjiemsft_0-1736215908659.png

vtangjiemsft_1-1736215934639.png

vtangjiemsft_2-1736215957549.png

(2) We can create a calculated column.

GR Date =
VAR _a =
    LOOKUPVALUE (
        'GR - 5G SvC_master ~ 2022 - Previous Backup Data'[GR Date],
        'GR - 5G SvC_master ~ 2022 - Previous Backup Data'[Site], [Internal Site ID]
    )
VAR _max_index =
    CALCULATE (
        MAX ( 'GR - 5G SvC_master since 2023 - Current Monthly Data'[Index] ),
        FILTER (
            'GR - 5G SvC_master since 2023 - Current Monthly Data',
            [Site] = EARLIER ( 'Distinct - Master Data'[Internal Site ID] )
        )
    )
VAR _b =
    CALCULATE (
        MAX ( 'GR - 5G SvC_master since 2023 - Current Monthly Data'[GR Date] ),
        FILTER (
            'GR - 5G SvC_master since 2023 - Current Monthly Data',
            [Site] = EARLIER ( 'Distinct - Master Data'[Internal Site ID] )
                && [Index] = _max_index
        )
    )
RETURN
    IF ( ISBLANK ( _a ), _b, _a )

(3) Then the result is as follows.

vtangjiemsft_3-1736216157328.png

 

Best Regards,

Neeko Tang

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

Thank you, it immediately works! 

Thumb up and accepted. 

Ritaf1983
Super User
Super User

Hi @jeongkim 

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-...
Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

I wrote the full data details and these details seem enough to write the 1 dax code, pls delete this reply so that others would reply and hope you can help other's query, not my query as I remember you that the last time replied similar.

 

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!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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

Top Solution Authors
Top Kudoed Authors