Forum Discussion

kolli002's avatar
kolli002
Regular Visitor
1 year ago
Solved

I have a issue with DAX

Hello Team,

I hope everyone is doing well!

I am facing an issue in my report.

I am expecting the output as below:

  • Employee Name: Nellaiappan Gomathinayagam

  • Week: 4–10 → 2 Days, and 11–17 → 3 Days (Month: Aug 2025)

But currently, I am getting the output incorrectly:

  • Under week 4–10 → only 1 day is showing

  • Week 11–17 is missing completely

I have used the calculation shown below.
Could you please assist me in resolving this issue?


Date Table calculation:

DateTable =
ADDCOLUMNS (
    CALENDAR ( MIN ( Attendance[date] ), MAX ( Attendance[date] ) ),
    "Year", YEAR ( [Date] ),
    "Month", FORMAT ( [Date], "MMM yyyy" ),
    "Week Start", [Date] - WEEKDAY ( [Date], 2 ) + 1,   -- Monday
    "Week End", ([Date] - WEEKDAY ( [Date], 2 ) + 1) + 6,  -- Week Start + 6
    "Week Number", WEEKNUM ( [Date], 2 ),               -- Mon–Sun
    "YearWeek",
        YEAR ( [Date] - WEEKDAY ( [Date], 2 ) + 1 ) * 100
        + WEEKNUM ( [Date] - WEEKDAY ( [Date], 2 ) + 1, 2 )
)

Week Label: 
VAR StartOfWeek = 'DateTable'[Date] - WEEKDAY ( 'DateTable'[Date], 2 ) + 1
VAR EndOfWeek   = StartOfWeek + 6
RETURN
    FORMAT ( StartOfWeek, "DD" ) & " - "
    & FORMAT ( EndOfWeek, "DD" ) & ", "
    & FORMAT ( EndOfWeek, "MMM" )

Days Present per Week =
CALCULATE (
    DISTINCTCOUNT ( Attendance[Date] ),
    KEEPFILTERS ( VALUES ( DateTable[Date] ) )
)
Source data screen shot is below:


Report output:

Relation ship in Model:

 



 

5 Replies

  • Hi kolli002,

    without usable data, I can only suggest to use a simpler code

    Days Present per Week =

    DISTINCTCOUNT ( Attendance[Date] )

     

    Does that work?

     

    If not, 

    can you please share the pbix via some cloud service? Or in alternative can you please include, in a usable format, not an image, a small set of rows for each of the tables involved in your request and show the data model in a picture, so that we can import the tables in Power BI and reproduce the data model. The subset of rows you provide, even is just a subset of the original tables, must cover your issue or question completely. Do not include sensitive information and do not include anything that is unrelated to the issue or question. Please show the expected outcome based on the sample data you provided and make sure, in case you show a Power BI visual, to clarify the columns used in the grouping sections of the visual.

     

    Need help uploading data? click here

     

    Want faster answers? click here

  • It would appear that you've created your "Days Present per Week" as a calculated column? 

     

    I don't think you need to change the syntax of your DAX. If you want it to change for each employee that you've selected create it as a measure instead. 

  • v-sdhruv's avatar
    v-sdhruv
    Icon for Community Support rankCommunity Support

    Hi kolli002 ,


    Just wanted to check if you got a chance to review the suggestion provided?
    If you need any assistance, please feel free to reach out so that we can assist you better.

    Thank you for reaching out on Microsoft Community Forum

  • v-sdhruv's avatar
    v-sdhruv
    Icon for Community Support rankCommunity Support

    Hi kolli002 ,
    I hope the explaination provided, has addressed your query.
    Since we didnt hear back, we would be closing this thread.
    If you need any assistance, feel free to reach out.

    Thank you