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
bzeeblitz
Helper IV
Helper IV

create new table based on 3 tables

 

Table Name:Demand ;Note:No duplicate Item Number
Item Numberonhand>9 monthsonhand>6 months
P123-AB-GG-AA-USLess Than 9 months onhandLess Than 6 months onhand
P123-AB-T-Z-USmore Than 9 months onhandmoreThan 6 months onhand
P123-E-BB-Z-USLess Than 9 months onhandLess Than 6 months onhand
215B14567more Than 9 months onhandmore Than 6 months onhand

 

onhand>9 months is a calcualted column where i used this formula 

Onhand>9months = if('Demand'[Months of Available Inventory]>9,"More than 9 months On-Hand","Less than 9 months On-Hand")

onhand>6 months is a calcualted column where i used this formula 

Onhand>6months = if('Demand'[Months of Available Inventory]>6,"More than 6 months On-Hand","Less than 6 months On-Hand")

Table Name :cycle;Note:Multiple times Item# found 
Item#Order:Card TypePO#
1-UPRIGHTCard21390
1-UPRIGHTcard21390
1-UPRIGHTcard21390
567890Non card21391
567890non card21391
567891card21392

 

Table Name : POItem;Note:Multiple times Item# found 
Item#CreatedwhenVendor name
36 uprightPO not created yesterdayWelldone
36 uprightPO not created yesterdaywelldone
36 uprightpO  created yesterdaywelldone
38 uprightPO not created yesterdayvendor1

createdwhen is a calculated column where i used this formula

CreatedWhen = if('POitem'[Date: Line Created].[Day] = day(TODAY()-1),"PO Created Yesterday","PO Not Created Yesterday")

 

Action steps:

I tried to create new table and used the below formula for retrieving values from above 3 tables and i can see below columns created but i need to add extra columns vendorname column from POitem Table and cardType column from cycle table and we need to also check for Item# respectively from these two table also there are possible of Item# occuring multiple times.

Kindly help

 

Below code runs for non blank values as well so we need to remove nonblankvalues for createdwhen column if its blank value incase

 

Table =

SELECTCOLUMNS(

VALUES('Demand'[Item Number]), -- Ensure only unique Item Numbers

"Greater than 9 Months On-Hand",

CALCULATE(MAX('Demand'[Onhand>9months])),

"Greater than 6 Months On-Hand",

CALCULATE(MAX('Demand'[Onhand>6months])),

"Item Number",

'Demand'[Item Number],

"CreatedWhen",

FIRSTNONBLANK(

'poitem'[CreatedWhen], -- This should be a single column

'poitem'[CreatedWhen] -- We are evaluating CreatedWhen for non-blank valu

1 ACCEPTED SOLUTION
DataNinja777
Super User
Super User

Hi @bzeeblitz ,

 

To achieve your desired result, we need to update your DAX formula to include the additional columns Vendor Name from the POItem table and Card Type from the Cycle table, while also ensuring that CreatedWhen handles non-blank values appropriately. Here’s the updated DAX for creating the new table:

Table =
SELECTCOLUMNS(
    VALUES('Demand'[Item Number]), -- Ensure only unique Item Numbers
    "Item Number", 'Demand'[Item Number],
    "Greater than 9 Months On-Hand", CALCULATE(MAX('Demand'[Onhand>9months])),
    "Greater than 6 Months On-Hand", CALCULATE(MAX('Demand'[Onhand>6months])),
    "CreatedWhen", 
    FIRSTNONBLANK(
        FILTER(
            'POItem',
            NOT(ISBLANK('POItem'[CreatedWhen]))
        )['CreatedWhen'],
        'POItem'[CreatedWhen]
    ),
    "Vendor Name", 
    FIRSTNONBLANK(
        FILTER(
            'POItem',
            NOT(ISBLANK('POItem'[CreatedWhen]))
        )['Vendor name'],
        'POItem'[Vendor name]
    ),
    "Card Type", 
    FIRSTNONBLANK(
        FILTER(
            'Cycle',
            'Cycle'[Item#] = 'Demand'[Item Number]
        )['Order:Card Type'],
        'Cycle'[Order:Card Type]
    )
)

The SELECTCOLUMNS function is used to create the new calculated table and explicitly define the columns required for the table. The column "Item Number" retrieves unique item numbers from the Demand table. The columns "Greater than 9 Months On-Hand" and "Greater than 6 Months On-Hand" use the CALCULATE function with MAX to extract the corresponding values. The "CreatedWhen" column retrieves the first non-blank value of CreatedWhen from the POItem table, ensuring only relevant entries are included. Similarly, the "Vendor Name" column retrieves the first non-blank Vendor Name from the POItem table. The "Card Type" column filters the Cycle table based on the matching Item# with the Demand table’s Item Number and retrieves the first non-blank value of Order:Card Type.

 

To handle non-blank values, the FILTER function is applied to ensure only rows with valid entries for CreatedWhen in the POItem table are considered. This ensures the resulting data is clean and adheres to the conditions specified.

 

When dealing with multiple occurrences of Item# in the Cycle or POItem tables, the FIRSTNONBLANK function is used to extract the first valid entry for each case. This approach is suitable for creating summary tables, but adjustments may be needed if more detailed or aggregated data is required.

 

Once this table is created, it can be used directly in Power BI visualizations to display the required data. If further modifications or enhancements are needed, those can be made based on specific requirements.

 

Best regards,

View solution in original post

1 REPLY 1
DataNinja777
Super User
Super User

Hi @bzeeblitz ,

 

To achieve your desired result, we need to update your DAX formula to include the additional columns Vendor Name from the POItem table and Card Type from the Cycle table, while also ensuring that CreatedWhen handles non-blank values appropriately. Here’s the updated DAX for creating the new table:

Table =
SELECTCOLUMNS(
    VALUES('Demand'[Item Number]), -- Ensure only unique Item Numbers
    "Item Number", 'Demand'[Item Number],
    "Greater than 9 Months On-Hand", CALCULATE(MAX('Demand'[Onhand>9months])),
    "Greater than 6 Months On-Hand", CALCULATE(MAX('Demand'[Onhand>6months])),
    "CreatedWhen", 
    FIRSTNONBLANK(
        FILTER(
            'POItem',
            NOT(ISBLANK('POItem'[CreatedWhen]))
        )['CreatedWhen'],
        'POItem'[CreatedWhen]
    ),
    "Vendor Name", 
    FIRSTNONBLANK(
        FILTER(
            'POItem',
            NOT(ISBLANK('POItem'[CreatedWhen]))
        )['Vendor name'],
        'POItem'[Vendor name]
    ),
    "Card Type", 
    FIRSTNONBLANK(
        FILTER(
            'Cycle',
            'Cycle'[Item#] = 'Demand'[Item Number]
        )['Order:Card Type'],
        'Cycle'[Order:Card Type]
    )
)

The SELECTCOLUMNS function is used to create the new calculated table and explicitly define the columns required for the table. The column "Item Number" retrieves unique item numbers from the Demand table. The columns "Greater than 9 Months On-Hand" and "Greater than 6 Months On-Hand" use the CALCULATE function with MAX to extract the corresponding values. The "CreatedWhen" column retrieves the first non-blank value of CreatedWhen from the POItem table, ensuring only relevant entries are included. Similarly, the "Vendor Name" column retrieves the first non-blank Vendor Name from the POItem table. The "Card Type" column filters the Cycle table based on the matching Item# with the Demand table’s Item Number and retrieves the first non-blank value of Order:Card Type.

 

To handle non-blank values, the FILTER function is applied to ensure only rows with valid entries for CreatedWhen in the POItem table are considered. This ensures the resulting data is clean and adheres to the conditions specified.

 

When dealing with multiple occurrences of Item# in the Cycle or POItem tables, the FIRSTNONBLANK function is used to extract the first valid entry for each case. This approach is suitable for creating summary tables, but adjustments may be needed if more detailed or aggregated data is required.

 

Once this table is created, it can be used directly in Power BI visualizations to display the required data. If further modifications or enhancements are needed, those can be made based on specific requirements.

 

Best regards,

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.