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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
PowerBiNoob37
Helper I
Helper I

Count Values from one table using based on month and year and add to another table (Pbix included)

Hi,

 

I have a bit of incident data coming from a sharepoint list, every row contains a date of incident and incident type which is a choice field.

 

Here is a sample of my data

PowerBiNoob37_1-1637622388371.png

 

 

So i need to count the amount of incidents every month and display them in a datamatrix like the following excel image below, i understand i can use a datamatrix and use the totals however i dont want that i need to create a new table that counts these values and displays them in the following way for futher analysis.

 

PowerBiNoob37_2-1637622530069.png

 

Here is my pbix file

 

https://1drv.ms/u/s!As_sc_x3g6_qkGn9-_Z88kpGqr3P

 

Any help would be appreciated.

1 ACCEPTED SOLUTION
HotChilli
Super User
Super User

Power Query:

Add a column for 1st day of the month (can do this from the interface->Select date column, go to Add Column-> From Date and Time on the ribbon)

Remove the original date column.

Group By StartOfMonth and Incident using Count Rows as aggregation.

This gives a 3 column table which is pretty good for storage and analysis.

If you want a table as shown, then Pivot the IncidentType column

View solution in original post

3 REPLIES 3
v-henryk-mstf
Community Support
Community Support

Hi @PowerBiNoob37 ,

 

Whether the advice given by @HotChilli  has solved your confusion, if the problem has been solved you can mark the reply for the standard answer to help the other members find it more quickly. If not, please point it out.


Looking forward to your feedback.


Best Regards,
Henry

HotChilli
Super User
Super User

Power Query:

Add a column for 1st day of the month (can do this from the interface->Select date column, go to Add Column-> From Date and Time on the ribbon)

Remove the original date column.

Group By StartOfMonth and Incident using Count Rows as aggregation.

This gives a 3 column table which is pretty good for storage and analysis.

If you want a table as shown, then Pivot the IncidentType column


@HotChilli wrote:

Power Query:

Add a column for 1st day of the month (can do this from the interface->Select date column, go to Add Column-> From Date and Time on the ribbon)

Remove the original date column.

Group By StartOfMonth and Incident using Count Rows as aggregation.

This gives a 3 column table which is pretty good for storage and analysis.

If you want a table as shown, then Pivot the IncidentType column


Thanks,

 

I didnt check my emails all day and so i didnt see your response and only came back here to post my answer, ill give you the solutions, because your right that would have been correct. But heres what i did to get the same results

 

I created a simple distinct measure in DAX

 

TotalInjuries = DISTINCTCOUNT(InjuriesTable[Injury Type])

 

and then created a table referencing the measure and using several if statments to group it by, it then created a table like i wanted and referenced the date as i set up a one to many relationship.

 

IncidentTotalTable = ADDCOLUMNS(IncidentTable, "Date", DATEVALUE(IncidentTable[InjuryDate]), "FAI" , IF( [Injury Type] = "FAI", [TotalInjuries] ), "MTI" , IF([Injury Type] = "MTI",  [TotalInjuries]), "LTI" , IF([Injury Type] = "LTI", [TotalInjuries]))

 

 I like your way better, except i would have had to create another table.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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