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
oandroido
Frequent Visitor

Combine values of multiple rows in one row

Hi,

 

Still very new to Power BI and trying to figure things out...

 

I have two columns; the first has States, and the second has # of sales per day. So, each state is listed multiple times, and I have a lot of data for sales per day as well.

 

I'd like to be able to combine this in a few ways, the first being keeping States to a single state per row, and averaging out the # of sales per day on that line.

 

That said, I'm not sure what the process(es) might be called, and haven't found the solution by searching.

 

The second part of this is a bit more complicated: I have dates for everything as well, and would also like to be able to view by Month, for example. If that's too much for one post I'll create a new thread.

Thanks in advance!

8 REPLIES 8
BobBI
Resolver III
Resolver III

Hi Oandroido,

 

Can you please share some sample data so provide your step by step solution.

 

thanks,

SS

Sure thing - 

StateSales Per DayDate
Pennsylvania411/24/2018
Pennsylvania442/14/2018
Pennsylvania724/25/2018
Pennsylvania827/19/2018
Pennsylvania278/8/2018
Florida222/1/2018
Florida481/24/2018
Florida375/4/2018
Florida253/12/2018
Florida727/14/2018
Florida734/4/2018
Florida224/5/2018
California263/26/2018
California269/5/2018
California7310/3/2018
California168/14/2018

Thanks

 

1)  Create a mesure in sales table to calculate average.

  

Avg Sale/day = CALCULATE(AVERAGE(Sales[Sales Per Day]),ALLEXCEPT(Sales,Sales[State]) )

 

ooput.JPG

 

2) Best practice -  Create a Date Table

Date = CALENDAR(date (2018,01,01),DATE(2018,31,12))

create data table.JPG

 

 

Add a column for 'Month'

Month = FORMAT('Date'[Date],"MMM")

link Date table with original sales table , Drag month from Date table and sales per day from sales table. ( second appreach would you Create month column within sales if you dont want to create date table but it is best practice to have date table)

 

 

data tt.JPGsample.JPG

 

Hope this helps,

SS

Hi Bob-

 

Sorry, still pretty new to this - could you explain what you mean when you say "Best practice -  Create a Date Table" ?

 

thanks

Anonymous
Not applicable

In the query editor select the State column then use the group by function, it's fairly self explanitory.

GroupBy.png

 

 

 

Thanks Tom - when I do that, it creates the correct table in the query editor, but when I Close & Apply, it breaks my visualizations and sends an error.

Anonymous
Not applicable

Did you rename any columns?

 

When you group by it sometimes puts a prefix iirc

Hi Tom - I didn't rename anything.

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.