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
RyanLMoran
Helper I
Helper I

Sum column based off of text data

Hello All:

 

     Quick question that I think will be relatively easy for sum.  I'm pulling in some data and transformed that data to only show me courses that have the "First Grade" name in them.  That way, I can ensure that I'm getting only the first grade courses and which teachers are teaching those courses.  But, I want to sum that so that I can have a Column that will show me Teacher Emily G is teaching 8 first grade courses.  Just to make it easier to get a quick look at what the load is for courses on that teacher.  This is listing out the courses but I need it summed to a total number.  I'm goinng to do the same thing to have a Kindergarten, Second Grade, Third Grade, etc... total columns for each grade.  That way we can see that Emily is teaching 2 Kindergarten courses,  8 First Grade Courses, 0 Second Grade courses, etc... and then a total in sum at the end to show 22 total elementary courses being taught by her.  Thank you!

 

RyanLMoran_0-1644253795600.png

 

17 REPLIES 17
KNP
Super User
Super User

There are many ways you can approach this depending on the data and model complexity.

I've attached a simple example PBIX.

Have a look and let me know if you have any questions.

 

Have I solved your problem?
Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;).
chrome-9xf-Zagzel-B

If you found this post helpful, please give Kudos.
It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen.
If you find my signature vaguely amusing, please give Kudos.
KIfp67uy-Sr
Proud to be a Super User!PBI-Super-User-Rank-30x30-1x
serpiva64
Super User
Super User

Hi, 

please provide not an image of data but some sample data in a format one can use.

 

Sure, like the PBIX file or how should I attach that?

KNP
Super User
Super User

Should be easy enough, can you please paste some data to work with? (not a screen shot)

 

Have I solved your problem?
Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;).
chrome-9xf-Zagzel-B

If you found this post helpful, please give Kudos.
It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen.
If you find my signature vaguely amusing, please give Kudos.
KIfp67uy-Sr
Proud to be a Super User!PBI-Super-User-Rank-30x30-1x

I'd be happy to.  Would I just attach the PBIX file that I currently have?

If the data is not sensitive, yes. You'll have to share a link to google drive or similar as attaching files is restricted. Alternatively, you could just paste some sample data directly.

 

Did you see the PBIX I attached earlier? Does this help?

 

Have I solved your problem?
Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;).
chrome-9xf-Zagzel-B

If you found this post helpful, please give Kudos.
It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen.
If you find my signature vaguely amusing, please give Kudos.
KIfp67uy-Sr
Proud to be a Super User!PBI-Super-User-Rank-30x30-1x

Hello:

    The sample report you sent over is essentially what I'm looking for.  The first column will list the teacher name, then across the top will list Kindergarten, first grade, second grade, etc...   with the row totaling the enrollments in each grade for the teacher and then at the bottom giving a total.  But, I'm not sure how I sum and total based on the text string as shown in the data that I have.  And to lay it out like you have it.  Thanks, I appreciate the help.

So if you go into Power Query (Transform Data) in the PBIX I attached, and look at the steps, you can see I added a custom column prior to pivoting. It is simply just a repeating 1 to give you something to sum on.

To deal with 'Kindergarten' you'd also need to alter the split, as it is currently splitting on " grade ", change it to " " << the first space.

 

Again, I'd be able to offer a more definitive answer with some sample data. 

 

Have I solved your problem?
Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;).
chrome-9xf-Zagzel-B

If you found this post helpful, please give Kudos.
It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen.
If you find my signature vaguely amusing, please give Kudos.
KIfp67uy-Sr
Proud to be a Super User!PBI-Super-User-Rank-30x30-1x

https://drive.google.com/file/d/1YxXx69jHEV-G69UB8flojNF85bbVFEvD/view?usp=sharing  

 

This should link you to a copy of the report.  Thank you!

Hi @RyanLMoran,

 

I've attached your PBIX (with some changes).

I can't update it as it has direct connections to Dataflows so I had to manually duplicate the tables as 'F' and 'T' to test. You can delete those.

 

Because I can't update it, the new column I added, 'Level', won't show until you open and update it.

Once you apply changes after opening, drag the new 'Level' field into the Columns for the bottom left pivot table.

KNP_0-1644340091911.png

Let me know if this works for you.

 

 

Have I solved your problem?
Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;).
chrome-9xf-Zagzel-B

If you found this post helpful, please give Kudos.
It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen.
If you find my signature vaguely amusing, please give Kudos.
KIfp67uy-Sr
Proud to be a Super User!PBI-Super-User-Rank-30x30-1x

This has a lot of the optionality that I'm looking for.  But, it's giving me all courses, where I need it to only show me the elementary courses, Kindergarten through Sixth Grade.  I don't think that creating a filter multiple times over is the best path forward i.e. one for Kindergarten, one for First Grade, and then try and sum them.  I'm trying to get it to output like:

 

Elementary Teacher by Grade Level Report

Teacher names

Grade K

Grade 1

Grade 2

Grade 3

Grade 4

Grade 5

Total

Teacher 1

 

 

 

 

 

 

 

Teacher 2

 

 

 

 

 

 

 

Teacher 3

 

 

 

 

 

 

 

Total

 

 

 

 

 

 

Total

 

Total Enrollments by Grade Level

Grade Level

Total Number of enrollments

Kindergarten

 

First

 

Second

 

Third

 

Fourth

 

Fifth

 

This is the trouble with only having one example of the data to work with, without all scenarios.

 

Couple of options to deal with this:

  1. Add a filter in power query (like the one you had originally for contains 'first grade') to only include the grades you're interested in. e.g. Contains 'first grade' or Contains 'second grade' etc.
  2. Add a report level or page level filter to the report. Use the 'Level' field I created. See gif below. Then select the grades you care about.

KNP_0-1644361877461.gif

 

The best way to do it would be to create a dimension that had grade and their parent category and then filter that way but that's a different conversation.

 

Have I solved your problem?
Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;).
chrome-9xf-Zagzel-B

If you found this post helpful, please give Kudos.
It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen.
If you find my signature vaguely amusing, please give Kudos.
KIfp67uy-Sr
Proud to be a Super User!PBI-Super-User-Rank-30x30-1x

Hi, if you want something like this (i duplicated the rows only changing in Name the grade):

serpiva64_1-1644336637580.png

You can add column with extract

serpiva64_2-1644336773912.png

then

add a conditional column

serpiva64_3-1644336834627.png

 

Then on the cnvas you only need

serpiva64_4-1644336915081.png

As you see it is not necessary to create many query (one for each grade), the filter on ACTIVE can semplify but you can also gain the same result with a slicer in the canvas

 

If this post isuseful to help you to solve your issue consider giving the post a thumbs up and accepting it as a solution !

 

 

 

 

For the value "Count of Name" Did you create a new column or field to do the totaling?

Thanks! I'll dive into this tonight, this looks to be along the lines of what I'm trying to get for output.  And, you're right, it is more efficient than trying to create a query for each elementary grade

I did see that, thank you.  I'm checking it out now.  And that's what I was wondering as I wasn't sure how to share any data over.  I'm somewhat hesitatant to publicly share it all as it's internal data for a school system:

 

RyanLMoran_0-1644269602949.png

RyanLMoran_1-1644269646779.png

I transformed the data to only show me the First Grade courses that are active, otherwise the table holds all classes included active and archive

RyanLMoran_3-1644269918552.png

RyanLMoran_4-1644269959627.png

 

RyanLMoran_2-1644269679716.png

 

 

I perfectly agree with you on the necessity of not sharing sensitive data.

If you want to share only the data you have just shared you can try this way

selecting the 2 column and With right click Copy

serpiva64_0-1644273011781.png

Then you can paste and also decide to keep only the rows you want

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.