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
Rt0790
Regular Visitor

Need Help _ DAX Week starting and Week ending total score for students

Hi All, I need your help your help writing a DAX statement (conditional/custom column) or Power query steps for the same to achieve the following result, here's a table that I am working on , Thank you so much in advance.

 

Student NameScoreYear Week WeekEndingStudentID
John85.2202339Sunday, Sep 24, 2023121
John85.2202340Sunday, Oct 1, 2023121
John51.7202341Sunday, Oct 8, 2023121
John54.3202342Sunday, Oct 15, 2023121
John38.3202343Sunday, Oct 22, 2023121
John20202344Sunday, Oct 29, 2023121
John41.9202345Sunday, Nov 5, 2023121
John50.4202346Sunday, Nov 12, 2023121
John30.9202347Sunday, Nov 19, 2023121
John52.6202348Sunday, Nov 26, 2023121
John0202349Sunday, Dec 3, 2023121

 

I need the week starting and ending running totals of the score column, Please see the expected result table. 

 

Expected result 

 

Student NameScoreYear Week WeekEndingStudentIDScore Week BeginningScore Week Ending
John85.2202339Sunday, Sep 24, 2023121085.2
John85.2202340Sunday, Oct 1, 202312185.2170.4
John51.7202341Sunday, Oct 8, 2023121170.4222.1
John54.3202342Sunday, Oct 15, 2023121222.1276.4
John38.3202343Sunday, Oct 22, 2023121276.4314.7
John20202344Sunday, Oct 29, 2023121314.7334.7
John41.9202345Sunday, Nov 5, 2023121334.7376.6
John50.4202346Sunday, Nov 12, 2023121376.6427
John30.9202347Sunday, Nov 19, 2023121427457.9
John52.6202348Sunday, Nov 26, 2023121457.9510.5
John0202349Sunday, Dec 3, 2023121510.5510.5
2 REPLIES 2
v-jincheng-msft
Community Support
Community Support

Hi Rt0790,

Hi, thanks for the information you have given.

Please use the following DAX to create Calculated columns:

Score Week Beginning =
VAR CurrentWeek = 'Table'[Week]
VAR CurrentScore = 'Table'[Score]
RETURN
    IF(
        CurrentWeek = MIN('Table'[Week]),
        0,
        CALCULATE(
            SUM('Table'[Score]),
            FILTER(
                ALL('Table'),
                'Table'[Week] < CurrentWeek
            )
        )
    )
Score Week Ending =
VAR CurrentWeek = 'Table'[Week]
VAR CurrentScore = 'Table'[Score]
RETURN
    IF(
        CurrentWeek = MIN('Table'[Week]),
        CurrentScore,
        CALCULATE(
            SUM('Table'[Score]),
            FILTER(
                ALL('Table'),
                'Table'[Week] <= CurrentWeek
            )
        )
    )

vjinchengmsft_0-1703757462220.png

An attachment for your reference. Hope it helps!

 

Best regards,
Community Support Team_ Joseph Ji

 

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

123abc
Community Champion
Community Champion

To achieve the expected result of calculating the running totals of the score column from the week starting to the week ending for each student, you can use DAX formulas in Power BI. Here's how you can create a new table or a calculated column to get the desired result:

  1. Create a New Table or Use a Calculated Column: You can create a new calculated table or use a calculated column to generate the running totals for each student based on the week starting and week ending.

Here's a DAX formula for the calculated table approach:

 

ExpectedResultTable =
VAR CurrentStudent = 'YourTableName'[Student Name]
VAR CurrentWeek = 'YourTableName'[Week]
RETURN
ADDCOLUMNS(
FILTER(
'YourTableName',
[Student Name] = CurrentStudent && [Week] <= CurrentWeek
),
"Score Week Beginning",
CALCULATE(
SUM('YourTableName'[Score]),
FILTER(
'YourTableName',
[Student Name] = CurrentStudent && [Week] <= CurrentWeek
)
),
"Score Week Ending",
CALCULATE(
SUM('YourTableName'[Score]),
FILTER(
'YourTableName',
[Student Name] = CurrentStudent && [Week] <= CurrentWeek
)
)
)

 

  1. Replace 'YourTableName': Make sure to replace 'YourTableName' with the actual name of your table where you have the student data.

  2. Apply the DAX Formula:

  • Go to Power BI Desktop.
  • Create a new table using the DAX formula provided above.
  • You will get a new table with columns "Score Week Beginning" and "Score Week Ending" that will give you the running totals based on the week starting and week ending for each student.

This DAX formula will calculate the running totals of the score column for each student from the starting week up to the current week, giving you the expected result table as shown in your example.

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.