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

Bar Chart with an average of each time range and with two columns of week day & end.

Hi everyone, 

I'm stuck with this issue:

I'm working one creating a bar chart with time (x-axis) and meter of electricity (y-axis). I have three different columns here, date, time and meter_total. Then I create a bar chart but it then shows all the value from each time. 

Screenshot 2023-06-30 103918.png

 

I would like to create a bar chart like this (with two columns) with the average data of the total_meter: 

- define the period of the time to calculate an average value of total_meter

- define the weekday and weekend and shows an average value of each column by the time period

Screenshot 2023-06-30 104122.png

 

Many thanks, appreciate it very much. 

1 ACCEPTED SOLUTION
confidentnwrong
Advocate I
Advocate I

First, add a column to define weekdays and weekends.

 

Work Day = if(WEEKDAY([Date],2)>=6,"Weekend","Weekday")

(Code from this post : Solved: Weekend and Weekday Analysis - Microsoft Fabric Community )


Then, in a vertical clustered bar chart, add 01z_meter_total to the Y-axis, and choose "average" using the dropdown button. Add 01z_time to the X-axis. Add the Work Day column to the Legend.

 

If this post helps, please consider accepting it as a solution.

View solution in original post

8 REPLIES 8
tomerbi
Frequent Visitor

The column is added but it seems there's something wrong with the code. It shows the red tag on the right side again like in power query editor as an error and I cannot proceed any further. 

 

Screenshot 2023-06-30 115301.png

confidentnwrong
Advocate I
Advocate I

First, add a column to define weekdays and weekends.

 

Work Day = if(WEEKDAY([Date],2)>=6,"Weekend","Weekday")

(Code from this post : Solved: Weekend and Weekday Analysis - Microsoft Fabric Community )


Then, in a vertical clustered bar chart, add 01z_meter_total to the Y-axis, and choose "average" using the dropdown button. Add 01z_time to the X-axis. Add the Work Day column to the Legend.

 

If this post helps, please consider accepting it as a solution.

Hi,

many thanks for your reply. 

When addinga a new column with the code, there's an error I cannot proceed further.  

Screenshot 2023-06-30 113449.png

Apologies for the confusion.

You are creating a column through powerquery, whereas the code I've given you is DAX (calculated column).

You need to click on your table, select "Table tools" at the top then "New column".

0Capture d'écran 2023-06-30 113942.png

 

Hi I could manage to get the weekDay now using 

= if (Date.DayOfWeek([01Z.Date],Day.Monday)+1)>=6 then "Weekend" else "Weekday"

However, I have another problem. After choosing average from the drop down of 01z_meter_total, the columns don't change. I think it's because each value of 01z_meter_total is unique to each time here below. 

Screenshot 2023-06-30 145452.png

 How can I set the time periods of the day to get an average of each period on the chart? 

 

Thank you. 

This is because your times are too precise.

You need to add a column where you round up or down the time.

For instance, 

RoundedTime = concatenate(
HOUR([01z_time])
, concatenate(":"
, MINUTE([01z_time))

returns a string value that you can read as the time to the minute.

You can get rid of the 2nd concatenate to have the time to the hour

 

The column is added but it seems there's something wrong with the code. It shows the red tag on the right side again like in power query editor as an error and I cannot proceed any further. 

Screenshot 2023-06-30 115301.png

Not sure why the 2 gets underlined, mine does too but I can use the column once I've pressed enter or clicked the checkmark button.

Capture d'écran 2023-06-30 141332.png

 

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.