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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
rebam12
Helper I
Helper I

dax query

i have several different columns like subject columns like this 

 

 

username  email               english    maths     scienece       computer     

abc      abc@gmail.com          0-25%      76-100%                  0-25%

 

like engish is 0-25% 

maths is 76-100% 

sceince is 0

and computer is 0-25%

 

and another table 

 

date usernameemail
8/21/2024 abcabc@gmail.com
7/21/2024 abcabc@gmail.com
7/11/2024 abcabc@gmail.com

so i want 

  1. Total hours assigned to the student according to how many sections the have completed up to their last login date

so here last login date is 8/21/2024

means i want to count columns like abc person compleete 3 subjects except sciecnce/

so i want 3 figure here ..

1 ACCEPTED SOLUTION

Hello @rebam12 - you can try the below logic

CompletedSubjects1 =
VAR LastLogin =
    CALCULATE(
        MAX(LoginHistory[date]),
        FILTER(
            LoginHistory,
            LoginHistory[username] = MAX(StudentSubjects[username])
        )
    )
VAR CompletedCount =
    SUMX(
        {
            IF (
                CONTAINSSTRING(StudentSubjects[english], "0-25%") ||
                CONTAINSSTRING(StudentSubjects[english], "26-50%") ||
                CONTAINSSTRING(StudentSubjects[english], "51-75%") ||
                CONTAINSSTRING(StudentSubjects[english], "76-100%"),
                1,
                0
            ),
            IF (
                CONTAINSSTRING(StudentSubjects[maths], "0-25%") ||
                CONTAINSSTRING(StudentSubjects[maths], "26-50%") ||
                CONTAINSSTRING(StudentSubjects[maths], "51-75%") ||
                CONTAINSSTRING(StudentSubjects[maths], "76-100%"),
                1,
                0
            ),
            IF (
                CONTAINSSTRING(StudentSubjects[science], "0-25%") ||
                CONTAINSSTRING(StudentSubjects[science], "26-50%") ||
                CONTAINSSTRING(StudentSubjects[science], "51-75%") ||
                CONTAINSSTRING(StudentSubjects[science], "76-100%"),
                1,
                0
            ),
            IF (
                CONTAINSSTRING(StudentSubjects[computer], "0-25%") ||
                CONTAINSSTRING(StudentSubjects[computer], "26-50%") ||
                CONTAINSSTRING(StudentSubjects[computer], "51-75%") ||
                CONTAINSSTRING(StudentSubjects[computer], "76-100%"),
                1,
                0
            )
        },
        [Value]
    )
RETURN
    CompletedCount

rajendraongole1_0-1725642899346.png

 

Hope this helps.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

4 REPLIES 4
rajendraongole1
Super User
Super User

Hi @rebam12 -Create a measure to get the last login date for each student

LastLoginDate =
CALCULATE(
    MAX(LoginHistory[date]),
    FILTER(
        LoginHistory,
        LoginHistory[username] = MAX(StudentSubjects[username])
    )
)

 

rajendraongole1_1-1725626603071.png

Create calculated column to count completed subjects: is more than 0%

CompletedSubjects =
VAR EnglishCompleted =
    IF (
        NOT(ISBLANK(StudentSubjects[english])) &&
        StudentSubjects[english] <> "0",
        1,
        0
    )
VAR MathsCompleted =
    IF (
        NOT(ISBLANK(StudentSubjects[maths])) &&
        StudentSubjects[maths] <> "0",
        1,
        0
    )
VAR ScienceCompleted =
    IF (
        NOT(ISBLANK(StudentSubjects[science])) &&
        StudentSubjects[science] <> "0",
        1,
        0
    )
VAR ComputerCompleted =
    IF (
        NOT(ISBLANK(StudentSubjects[computer])) &&
        StudentSubjects[computer] <> "0",
        1,
        0
    )
RETURN
    EnglishCompleted + MathsCompleted + ScienceCompleted + ComputerCompleted

 

rajendraongole1_0-1725626566455.png

 

Hope this helps.

 

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





is this necessary to create var for each subjects ? what if there is 15 subjects then bit difficult to create 15 variables .... is there any other alternative for this ?

Hello @rebam12 - you can try the below logic

CompletedSubjects1 =
VAR LastLogin =
    CALCULATE(
        MAX(LoginHistory[date]),
        FILTER(
            LoginHistory,
            LoginHistory[username] = MAX(StudentSubjects[username])
        )
    )
VAR CompletedCount =
    SUMX(
        {
            IF (
                CONTAINSSTRING(StudentSubjects[english], "0-25%") ||
                CONTAINSSTRING(StudentSubjects[english], "26-50%") ||
                CONTAINSSTRING(StudentSubjects[english], "51-75%") ||
                CONTAINSSTRING(StudentSubjects[english], "76-100%"),
                1,
                0
            ),
            IF (
                CONTAINSSTRING(StudentSubjects[maths], "0-25%") ||
                CONTAINSSTRING(StudentSubjects[maths], "26-50%") ||
                CONTAINSSTRING(StudentSubjects[maths], "51-75%") ||
                CONTAINSSTRING(StudentSubjects[maths], "76-100%"),
                1,
                0
            ),
            IF (
                CONTAINSSTRING(StudentSubjects[science], "0-25%") ||
                CONTAINSSTRING(StudentSubjects[science], "26-50%") ||
                CONTAINSSTRING(StudentSubjects[science], "51-75%") ||
                CONTAINSSTRING(StudentSubjects[science], "76-100%"),
                1,
                0
            ),
            IF (
                CONTAINSSTRING(StudentSubjects[computer], "0-25%") ||
                CONTAINSSTRING(StudentSubjects[computer], "26-50%") ||
                CONTAINSSTRING(StudentSubjects[computer], "51-75%") ||
                CONTAINSSTRING(StudentSubjects[computer], "76-100%"),
                1,
                0
            )
        },
        [Value]
    )
RETURN
    CompletedCount

rajendraongole1_0-1725642899346.png

 

Hope this helps.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





the easiest option is to model your data better.

I.e subjects as rows not columns

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.