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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
daicaboy
Frequent Visitor

Calculator column condition issue

Hi everybody,

I have a data like data1 and i want to count how many product meet the condition. If the number sale of product for each store more than 10 is the Good sales, and less is Bad Sales.

Data 1

StoreDateProductSale
NY01/01/2020Computer20
NY01/01/2020Phone2
NY05/10/2020Headphone5
LA01/02/2020Computer2
NY01/02/2020Phone4
LA10/05/2020Headphone1
LA01/02/2020Computer4
De06/07/2020Phone5
De09/08/2020Headphone6
De10/02/2020Headphone3

 

Report

StoreGood salesBad sales
NY  
LA  
De  

 

I'm so appreciate for any help from you guys. Thanks

2 ACCEPTED SOLUTIONS
collinsg
Super User
Super User

Good day daicaboy,

To classify the data in Power Query you could use this approach,

  1. Group the data by store, summing the "Sale" column (call this summed column "Good/Bad" in anticipation of the next step).
  2. Transform the summed sale column from a number to "Good" or "Bad" depending on the value of the summed sales.
  3. Expand the table.
  4. Create a matrix visual with "Store" on rows, "Good or Bad" on columns and a sum of sales for values.

This yields,

collinsg_0-1705567260279.png

Here is code I used. I had copied your data into a table in Excel which I called "SalesTable" and then started by loading that table into Power BI Desktop.

let
Source = Excel.Workbook(File.Contents("PUT YOUR FILE SPECIFICAION HERE IF LOADING FROM EXCEL"), null, true),
SalesTable_Table = Source{[Item="SalesTable",Kind="Table"]}[Data],
#"Changed Type" = Table.TransformColumnTypes(SalesTable_Table,{{"Store", type text}, {"Date", type date}, {"Product", type text}, {"Sale", Int64.Type}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"Store"}, {{"Good/Bad", each List.Sum([Sale]), type nullable number}, {"All Rows", each _, type table [Store=nullable text, Date=nullable date, Product=nullable text, Sale=nullable number]}}),
#"Classify as Good/Bad" = Table.TransformColumns( #"Grouped Rows", {{"Good/Bad", each if _>10 then "Good" else "Bad"}} ),
#"Expanded All Rows" = Table.ExpandTableColumn(#"Classify as Good/Bad", "All Rows", {"Date", "Product", "Sale"}, {"Date", "Product", "Sale"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Expanded All Rows",{{"Good/Bad", type text}})
in
#"Changed Type1   

 Hope this helps

View solution in original post

v-kaiyue-msft
Community Support
Community Support

Hi @daicaboy ,

Please follow these steps:

1.Create calculated columns and write formulas.

Column =

var _stroe = 'Table'[Store]

VAR _sum_sale = CALCULATE(SUM('Table'[Sale]),FILTER('Table',_stroe = 'Table'[Store]))

RETURN

IF(_sum_sale > 10,

"Good sales",

"Bad sales")

2.Getting results.

vkaiyuemsft_0-1705570036658.png

3.Create the matrix in the report view.

vkaiyuemsft_1-1705570036659.png

vkaiyuemsft_2-1705570103980.png

If your Current Period does not refer to this, please clarify in a follow-up reply.

 

Best Regards,

Clara Gong

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

3 REPLIES 3
daicaboy
Frequent Visitor

Thanks you all. Both work fine for me. You guys help me a lot.

v-kaiyue-msft
Community Support
Community Support

Hi @daicaboy ,

Please follow these steps:

1.Create calculated columns and write formulas.

Column =

var _stroe = 'Table'[Store]

VAR _sum_sale = CALCULATE(SUM('Table'[Sale]),FILTER('Table',_stroe = 'Table'[Store]))

RETURN

IF(_sum_sale > 10,

"Good sales",

"Bad sales")

2.Getting results.

vkaiyuemsft_0-1705570036658.png

3.Create the matrix in the report view.

vkaiyuemsft_1-1705570036659.png

vkaiyuemsft_2-1705570103980.png

If your Current Period does not refer to this, please clarify in a follow-up reply.

 

Best Regards,

Clara Gong

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

collinsg
Super User
Super User

Good day daicaboy,

To classify the data in Power Query you could use this approach,

  1. Group the data by store, summing the "Sale" column (call this summed column "Good/Bad" in anticipation of the next step).
  2. Transform the summed sale column from a number to "Good" or "Bad" depending on the value of the summed sales.
  3. Expand the table.
  4. Create a matrix visual with "Store" on rows, "Good or Bad" on columns and a sum of sales for values.

This yields,

collinsg_0-1705567260279.png

Here is code I used. I had copied your data into a table in Excel which I called "SalesTable" and then started by loading that table into Power BI Desktop.

let
Source = Excel.Workbook(File.Contents("PUT YOUR FILE SPECIFICAION HERE IF LOADING FROM EXCEL"), null, true),
SalesTable_Table = Source{[Item="SalesTable",Kind="Table"]}[Data],
#"Changed Type" = Table.TransformColumnTypes(SalesTable_Table,{{"Store", type text}, {"Date", type date}, {"Product", type text}, {"Sale", Int64.Type}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"Store"}, {{"Good/Bad", each List.Sum([Sale]), type nullable number}, {"All Rows", each _, type table [Store=nullable text, Date=nullable date, Product=nullable text, Sale=nullable number]}}),
#"Classify as Good/Bad" = Table.TransformColumns( #"Grouped Rows", {{"Good/Bad", each if _>10 then "Good" else "Bad"}} ),
#"Expanded All Rows" = Table.ExpandTableColumn(#"Classify as Good/Bad", "All Rows", {"Date", "Product", "Sale"}, {"Date", "Product", "Sale"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Expanded All Rows",{{"Good/Bad", type text}})
in
#"Changed Type1   

 Hope this helps

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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

Top Solution Authors
Top Kudoed Authors