Forum Discussion

MSiwek's avatar
MSiwek
Helper I
1 year ago

Matrix in PowerBi shows same values for each row

Hi All,

I have a problem with connections/measure because my simple measure shows same value for each row. 

I'm using "Nazwa grupy" from "Zmiany" Date from "Kalendarz" and my measure is in values:

Ilość serwisów = COUNTROWS(
    FILTER(
        SAX,
        (SAX[SVCDATECREATED].[Rok] = 2024 || SAX[SVCDATECREATED].[Rok] = 2025) &&
        NOT(ISBLANK(SAX[SERVICE]))
    )
)
I can't give you a file cause of the organizational policy but maybe someone would know what happened with my data?

26 Replies

  • Deku's avatar
    Deku
    Super User

    Added keepfilters to intersect the current a calculated filter contexts.

     

    Ilość serwisów = COUNTROWS(

        Keepfilters(

    FILTER(

            SAX,

            (SAX[SVCDATECREATED].[Rok] = 2024 || SAX[SVCDATECREATED].[Rok] = 2025) &&

            NOT(ISBLANK(SAX[SERVICE]))

        )

    )

    )

    • MSiwek's avatar
      MSiwek
      Helper I

      Deku information below:

       

      KEEPFILTERS function can only be used as a top level filter argument of CALCULATE and CALCULATETABLE or with a table argument of a function performing a table scan.

      • Deku's avatar
        Deku
        Super User

        Ilość serwisów =

        Calculate(

        COUNTROWS( SAX ),

        Keepfilters(

        FILTER(

        SAX,

        (SAX[SVCDATECREATED].[Rok] = 2024 || SAX[SVCDATECREATED].[Rok] = 2025) &&

        NOT(ISBLANK(SAX[SERVICE]))

        )

        )

        )

  • There is no filter flow from your Zimiany table to your SAX table so you will not get a proper filter contect if you use the "Nazwa grupy" from "Zmiany" and the measure built off of SAX. 

     

    Without knowing your datamodel it is difficult to give you the best path forward.  With that said I would default to Roche’s maxim and say you probably should look at doing some upstream work. 

     

    Please mark this post as solution if it helps you. Appreciate Kudos.

    • MSiwek's avatar
      MSiwek
      Helper I

      I can make a direct connection between "Zmiany" and "SAX" because I can improve my sql query or merge data in PQ to have also column SaxName in "Zmiany" table but what about Employees and Presence States table? If I made direct connection between "Zmiany" and "SAX" "SaxNames" wouldn't be used and could be delated.

      • MSiwek's avatar
        MSiwek
        Helper I

        andrewsommer i made a sample of my data. 

        SAX:

        SVCDATECREATEDSERVICESVCCREATEDBY
        25.03.2025NAME OF SERVICE 1SWK
        01.03.2025NAME OF SERVICE 2KWS
        14.03.2025

        NAME OF SERVICE 1

        SWK

        Połączenie:

        SVCCREATEDBY
        SWK
        KWS

        SaxNames:

        SaxnameUserId
        SWK1
        KWS2

        Zmiany:

        EmployeeIdNazwa grupy
        1Dep 1
        2Dep 2

        Employees:

        EmployeeIdNAME AND SURNAME
        1MICHAEL TEST
        2JACOB TEST

        PresenceStates

        EmployeeIdWorkinHoursDate
        1801.01.2025
        2802.01.2025

         

        Would this be helpful?

  • v-ssriganesh's avatar
    v-ssriganesh
    Community Support

    Hi MSiwek,
    Thank you for bringing your query to the Microsoft Fabric Community Forum.

    I have reproduced your issue using my sample data and followed the steps below to achieve the expected result. I have also attached a screenshot of the expected output and the .pbix file for your reference.

    Steps Taken to Reproduce & Solve the Issue:

    • I have Created six tables in Power BI using the Enter Data feature and established relationships between them.
    • Created the following measure to correctly count services per department:
    Total Services =
    
    VAR SelectedDept = SELECTEDVALUE(Zmiany[Nazwa grupy])
    
    RETURN
    
    CALCULATE(
    
        COUNT(SAX[SERVICE]),
    
        TREATAS(VALUES(Zmiany[EmployeeId]), SaxNames[UserId])
    
    )

     

    Expected Output Screenshot for your reference:


    Thank you, Deku & andrewsommer for sharing your valuable insights.

     

    If this is helpful, please “Accept it as a solution” and give a "kudos" to assist other community members in resolving similar issues more efficiently.
    Thank you.

    • MSiwek's avatar
      MSiwek
      Helper I

      v-ssriganesh it's almost done. I made mistake in describing table "Zmiany" beacuse it should look like this

      EmployeeIdNazwa grupyDate FromDate to
      1Dep 101.01.202531.03.2025
      2Dep 201.01.2025 
      1Dep 301.04.2025 

       

      So that's mean that one Employee can work in one department and could get promotion to another department and now I have problem with thing when I'm using Nazwa grupy from "Zmiany" in rows, SVCDATECREATED from "SAX" in columns and measure Total Services in values I have EmployeeId in two deparments but measure show the same value for each month and each deparment. So my matrix in powerbi looks like 

      Dep 1JanuaryFebruaryMarch
          EmloyeeId 1100200300
      Dep 2   
          EmloyeeId 1100200300

      And should look like this:

      Dep 1JanuaryFebruaryMarchApril
          EmloyeeId 11002003000
      Dep 2    
          EmloyeeId 1100200300200

      And I think the measure should also have something with dates.

      • v-ssriganesh's avatar
        v-ssriganesh
        Community Support

        Hi MSiwek,

        Thank you for providing the updated details about the Zmiany table and the expected output. I understand the issue now: the measure wasn’t accounting for the time-dependent department assignments in the Zmiany table (using Date From and Date to). This caused the same values to appear for each department for EmployeeId 1, even though the employee moved from Dep 1 to Dep 3 on 01.04.2025. I’ve updated the solution below to fix this by modifying the Total Services measure to filter services based on the date range during which an employee was in a department.

        • I’ve updated the Zmiany table in my sample data to match your corrected structure.
        • You mentioned using "Date from ‘Kalendarz’," so I assume you have a Calendar table. If not, create one to manage dates consistently:
        Calendar = CALENDAR(DATE(2025, 1, 1), DATE(2025, 12, 31))
        • The previous measure didn’t account for the date range in the Zmiany table, which caused the same values to appear for each department. Here’s the updated measure:
        Total Services =
        
        CALCULATE(
        
            COUNT(SAX[SERVICE]),
        
            FILTER(
        
                Zmiany,
        
                Zmiany[EmployeeId] IN VALUES(SaxNames[UserId]) &&
        
                'Calendar'[Date] >= Zmiany[Date From] &&
        
                (Zmiany[Date to] IS BLANK || 'Calendar'[Date] <= Zmiany[Date to])
        
            ),
        
            TREATAS(VALUES('Calendar'[Date]), SAX[SVCDATECREATED])
        
        )
        • This measure ensures that services are only counted for the department an employee was in during the date range specified in Zmiany[Date From] and Zmiany[Date to].
        • The TREATAS function ensures the date filter from the Calendar table (used in the matrix columns) is applied to SAX[SVCDATECREATED].

        If you find this information useful, please “Accept it as a solution” and give it a 'Kudos' to assist others in locating it easily.
        Thank you.