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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
LACEG
New Member

Calculating the same value in 2 different columns

Hi All,

 

I am new to Power BI and think it is a great analysis tool.  I am attempting to create a report but I am facing issues (due to being new to the tool).

 

The intention of the report is to show the number of imports (column 1) and the number of exports (column 2) from a specific shipping port (location) for a given customer (row 1).

 

This mean that the port needs to be selected before the report is generated.

 

Once the port has been chosen, then this value needs to be checked against every record in the customer table looking at the 'import' and 'export' columns.  If the chosen port matches either the import or export values then this should be counted else it should not be counted. 

 

Here is an example:

This is how the underlying data looks:

ConsigneeImportExport
Customer 1LISNYC
Customer 2NYCLEI
Customer 3LEINYC
Customer 4NYCLIS
Customer 5LEINYC
Customer 6NYCLIS
Customer 7LEINYC
Customer 8LEINYC
Customer 9LEINYC
Customer 10NYCLIS

 

So if the 'Port' was selected as 'LIS' then the following values should be returned:

PortLIS 
CustomerImportsExportsTotal
Customer 11 1
Customer 4 11
Customer 6 11
Customer 10 11
Total134

 

Can anyone give me some pointers on how I can calculate the chosen port against the I'mport' and 'Export' columns in the underlying data table?

 

Thank you in advance.

1 ACCEPTED SOLUTION
greggyb
Resident Rockstar
Resident Rockstar

  1. It's been five hours, calm down.
  2. Here's a sample .pbix for you.

 

You need to unpivot your import and export columns (this is done in Edit Queries). This allows a much cleaner measure setup:

 

// DAX
// Measures

Total =
COUNTROWS( FactShipment )

Imports =
CALCULATE(
    [Total]
    ,FactShipment[ShipmentType] = "Import"
)

Exports =
CALCULATE(
    [Total]
    ,FactShipment[ShipmentType] = "Export"
)

View solution in original post

4 REPLIES 4
LACEG
New Member

Can anyone help me with my query? 🙂

greggyb
Resident Rockstar
Resident Rockstar

  1. It's been five hours, calm down.
  2. Here's a sample .pbix for you.

 

You need to unpivot your import and export columns (this is done in Edit Queries). This allows a much cleaner measure setup:

 

// DAX
// Measures

Total =
COUNTROWS( FactShipment )

Imports =
CALCULATE(
    [Total]
    ,FactShipment[ShipmentType] = "Import"
)

Exports =
CALCULATE(
    [Total]
    ,FactShipment[ShipmentType] = "Export"
)

Thank you, this solution you have provided has done it Smiley Happy

Thank you greggyb - I will implement this now.

 

I apologise for my eagerness.

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.