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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
MigWare
Helper I
Helper I

Create a new column filtering values from column A and retrieve the correspondent value from columnB

Hi,

I have the following two columns in a table, Product and Value, and I need to create a third column that would have the values of Value after being filtered by Column A.

Example: New column would have all the Value of the Products that are not GAS

ProductValue
GAS37,00
GAS37,00
GAS36,00
GAS38,01
GAS35,00
FOOD37,00
GAS37,00
GAS37,00
FOOD32,24
FOOD34,29
FOOD29,70
FOOD32,05
GAS32,62
FOOD43,57
GAS38,43
GAS22,01
FOOD46,09
FOOD55,41
FOOD26,64
GAS37,57
FOOD40,16
GAS40,17
FOOD31,55
WATER40,38
FOOD36,05
FOOD35,56
FOOD36,83
FOOD35,69
WATER36,28
GAS38,00
GAS59,51
GAS38,12
GAS37,52
GAS54,82
FOOD50,51
FOOD52,44
FOOD46,23
FOOD53,00
GAS40,53
6 REPLIES 6
Icey
Community Support
Community Support

Hi @MigWare ,

 

I am not very clear what you want. Some possible requirements:

 

1. Create one column or measure to get the sum values of each product.

Column = CALCULATE ( SUM ( 'Table'[Value] ), ALLEXCEPT ( 'Table', 'Table'[Product] ) )
Measure = CALCULATE ( SUM ( 'Table'[Value] ), ALLEXCEPT ( 'Table', 'Table'[Product] ) )

re1.PNG

 

2. You want to show the sum value of each product, expect for the selected product.

a. Create a table.

Product Filter = VALUES('Table'[Product])

b. Create a measure.

Condition = IF ( MAX ( 'Table'[Product] ) IN VALUES ( 'Product Filter'[Product] ), 1, 0 )

c. Put the condition measure on "Filters on this visual" of the visuals you want to filter.

re2.PNG

re2.gif

 

BTW, .pbix file attached.

 

 

Best Regards,

Icey

 

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

thanks but that was not the aim of my question, trying to make it clear.

What I have in the table:

ProductValue
GAS37,00
GAS37,00
GAS36,00
GAS38,01
GAS35,00
FOOD37,00
GAS37,00
GAS37,00
FOOD32,24
FOOD34,29
FOOD29,70
FOOD32,05
GAS32,62
FOOD43,57
GAS38,43
GAS22,01
FOOD46,09
FOOD55,41
FOOD26,64
GAS37,57
FOOD40,16
GAS40,17
FOOD31,55
WATER40,38
FOOD36,05
FOOD35,56
FOOD36,83
FOOD35,69
WATER36,28
GAS38,00
GAS59,51
GAS38,12
GAS37,52
GAS54,82
FOOD50,51
FOOD52,44
FOOD46,23
FOOD53,00
GAS40,53

 

What I want to achieve:

 

ProductValueObjective
GAS37,000
GAS37,000
GAS36,000
GAS38,010
GAS35,000
FOOD37,0037,00
GAS37,000
GAS37,000
FOOD32,2432,24
FOOD34,2934,29
FOOD29,7029,70
FOOD32,0532,05
GAS32,620
FOOD43,5743,57
GAS38,430
GAS22,010
FOOD46,0946,09
FOOD55,4155,41
FOOD26,6426,64
GAS37,570
FOOD40,1640,16
GAS40,170
FOOD31,5531,55
WATER40,3840,38
FOOD36,0536,05
FOOD35,5635,56
FOOD36,8336,83
FOOD35,6935,69
WATER36,2836,28
GAS38,000
GAS59,510
GAS38,120
GAS37,520
GAS54,820
FOOD50,5150,51
FOOD52,4452,44
FOOD46,2346,23
FOOD53,0053,00
GAS40,530

 

use an IF function.

It is better to do this in Power Query, but I'll give both PQ and DAX:

Power Query:

Add a conditional column that will essentially generate this formula:

if [Product] = "GAS" then 0 else [Value]

2020-05-12 10_54_43-.png

It will return this table

2020-05-12 10_54_15-Untitled - Power Query Editor.png

If you want a calculated column (not advised), use this formula:

Objective = 
IF(
    'Table'[Product] = "GAS",
    0,
    'Table'[Value]
)

2020-05-12 10_52_28-Untitled - Power BI Desktop.png

 

In general, try to avoid calculated columns. There are times to use them, but it is rare. Getting data out of the source system, creating columns in Power Query, or DAX Measures are usually preferred to calculated columns. See these references:
Calculated Columns vs Measures in DAX
Calculated Columns and Measures in DAX
Storage differences between calculated columns and calculated tables
Creating a Dynamic Date Table in Power Query

 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

thanks, that was the objective. One question, if i want to add another product on the DAX expression

Objective = 
IF(
    'Table'[Product] = "GAS",
    0,
    'Table'[Value]
)

, is that possible? I´ve tried to use 'Table'[Product] = {"GAS","FOOD"} but i get an error saying a table of multiple values was supplied where a single value was expected 

Use the IN operator.

Objective = 
IF(
    'Table'[Product] in {"GAS","FOOD"},
    0,
    'Table'[Value]
)


Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting
edhans
Super User
Super User

If your table is called sample, the following calculated column will work.

 

EDIT: Not sure of your requirement. You might need to change the 7th line below to <> CurrentProduct.

If that isn't right either, be clearer on your expected result please with some sample output.

 

Total Values = 
VAR CurrentProduct = 'Sample'[Product]
RETURN
SUMX(
    FILTER(
        ALL('Sample'),
        'Sample'[Product] = CurrentProduct
    ),
    'Sample'[Value]
)

 

2020-05-08 10_19_02-Untitled - Power BI Desktop.png



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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