Forum Discussion

Swami_om's avatar
Swami_om
Regular Visitor
3 months ago
Solved

Enhancement Request – Add Visit Frequency Count to Employee Location Measure

In the below measure, I am currently retrieving the list of locations/cities visited by each employee.

I would now like to enhance the logic to additionally display how many times the employee visited each respective city/location.

Please modify the existing measure accordingly and provide the updated DAX expression.



DAX Code:


Visited Cities (Final v2) =
VAR EmployeeEmail =
    SELECTEDVALUE('WorkdayBridge'[Email])

VAR OfficeCity =
    SELECTEDVALUE('WorkdayBridge'[Office City])

VAR SelectedLocation =
    SELECTEDVALUE('WorkdayBridge'[Location])

/* Ensure employee is part of selected location */
VAR IsEmployeeInLocation =
    CALCULATE(
        COUNTROWS('WorkdayBridge'),
        REMOVEFILTERS(NetworkData),
        'WorkdayBridge'[Email] = EmployeeEmail,
        'WorkdayBridge'[Location] = SelectedLocation
    )

/* Check if employee has at least one visit to Office City */
VAR HasOfficeVisit =
    CALCULATE(
        COUNTROWS(NetworkData),
        REMOVEFILTERS(NetworkData),
        NetworkData[UserEmail] = EmployeeEmail,
        NetworkData[SP.City] = OfficeCity
    )

/* Get other visited cities */
VAR OtherCities =
    CALCULATE(
        CONCATENATEX(
            DISTINCT(NetworkData[SP.City]),
            NetworkData[SP.City],
            " | ",
            NetworkData[SP.City],
            ASC
        ),
        REMOVEFILTERS(NetworkData),
        NetworkData[UserEmail] = EmployeeEmail,
        NetworkData[SP.City] <> OfficeCity
    )

RETURN
IF(
    NOT ISBLANK(EmployeeEmail)
        && NOT ISBLANK(OfficeCity)
        && IsEmployeeInLocation > 0,
   
    IF(
        HasOfficeVisit > 0,
        IF(
            ISBLANK(OtherCities),
            OfficeCity,
            OfficeCity & " | " & OtherCities
        ),
        ""
    ),
    BLANK()
)

 

  • Hey Swami_om ,

    upload a PBIX file to OneDrive or Dropbox, that contains sample data but besides represents your semantic model (realtionships, calculated columns, and measures).

    Next to that describe the expected outcome based on the sample data you provided.

    Regards,
    Tom

  • Welcome to the forums.

     

    Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
    Do not include sensitive information. Do not include anything that is unrelated to the issue or question.
    Please show the expected outcome based on the sample data you provided.

    Need help uploading data? https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-p/963216
    Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

  • Hi Swami_om,

    Hope you're doing well!

     

    I agree with lbendlin and TomMartens.

     

    Can you confirm that you want an output loke this ?

    New York (5) | Chicago (2) | Austin (1)

     

    If yes, here's a proposition to test it that can maybe helps you :

     

    Visited Cities (Final v2) =
    VAR EmployeeEmail =
    SELECTEDVALUE('WorkdayBridge'[Email])

    VAR OfficeCity =
    SELECTEDVALUE('WorkdayBridge'[Office City])

    VAR SelectedLocation =
    SELECTEDVALUE('WorkdayBridge'[Location])

    /* Ensure employee is part of selected location */
    VAR IsEmployeeInLocation =
    CALCULATE(
    COUNTROWS('WorkdayBridge'),
    REMOVEFILTERS(NetworkData),
    'WorkdayBridge'[Email] = EmployeeEmail,
    'WorkdayBridge'[Location] = SelectedLocation
    )

    /* Check if employee has at least one visit to Office City */
    VAR HasOfficeVisit =
    CALCULATE(
    COUNTROWS(NetworkData),
    REMOVEFILTERS(NetworkData),
    NetworkData[UserEmail] = EmployeeEmail,
    NetworkData[SP.City] = OfficeCity
    )

    /* Build Office City string with visit count */
    VAR OfficeCityWithCount =
    OfficeCity & " (" & HasOfficeVisit & ")"

    /* Get other visited cities with visit counts */
    VAR OtherCities =
    CALCULATE(
    CONCATENATEX(
    ADDCOLUMNS(
    DISTINCT(NetworkData[SP.City]),
    "@VisitCount",
    CALCULATE(
    COUNTROWS(NetworkData),
    ALLEXCEPT(NetworkData, NetworkData[SP.City])
    )
    ),
    NetworkData[SP.City] & " (" & [@VisitCount] & ")",
    " | ",
    NetworkData[SP.City],
    ASC
    ),
    REMOVEFILTERS(NetworkData),
    NetworkData[UserEmail] = EmployeeEmail,
    NetworkData[SP.City] <> OfficeCity
    )

    RETURN
    IF(
    NOT ISBLANK(EmployeeEmail)
    && NOT ISBLANK(OfficeCity)
    && IsEmployeeInLocation > 0,

    IF(
    HasOfficeVisit > 0,
    IF(
    ISBLANK(OtherCities),
    OfficeCityWithCount,
    OfficeCityWithCount & " | " & OtherCities
    ),
    ""
    ),
    BLANK()
    )

6 Replies

  • Welcome to the forums.

     

    Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
    Do not include sensitive information. Do not include anything that is unrelated to the issue or question.
    Please show the expected outcome based on the sample data you provided.

    Need help uploading data? https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-p/963216
    Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

  • Hi Swami_om,

    Hope you're doing well!

     

    I agree with lbendlin and TomMartens.

     

    Can you confirm that you want an output loke this ?

    New York (5) | Chicago (2) | Austin (1)

     

    If yes, here's a proposition to test it that can maybe helps you :

     

    Visited Cities (Final v2) =
    VAR EmployeeEmail =
    SELECTEDVALUE('WorkdayBridge'[Email])

    VAR OfficeCity =
    SELECTEDVALUE('WorkdayBridge'[Office City])

    VAR SelectedLocation =
    SELECTEDVALUE('WorkdayBridge'[Location])

    /* Ensure employee is part of selected location */
    VAR IsEmployeeInLocation =
    CALCULATE(
    COUNTROWS('WorkdayBridge'),
    REMOVEFILTERS(NetworkData),
    'WorkdayBridge'[Email] = EmployeeEmail,
    'WorkdayBridge'[Location] = SelectedLocation
    )

    /* Check if employee has at least one visit to Office City */
    VAR HasOfficeVisit =
    CALCULATE(
    COUNTROWS(NetworkData),
    REMOVEFILTERS(NetworkData),
    NetworkData[UserEmail] = EmployeeEmail,
    NetworkData[SP.City] = OfficeCity
    )

    /* Build Office City string with visit count */
    VAR OfficeCityWithCount =
    OfficeCity & " (" & HasOfficeVisit & ")"

    /* Get other visited cities with visit counts */
    VAR OtherCities =
    CALCULATE(
    CONCATENATEX(
    ADDCOLUMNS(
    DISTINCT(NetworkData[SP.City]),
    "@VisitCount",
    CALCULATE(
    COUNTROWS(NetworkData),
    ALLEXCEPT(NetworkData, NetworkData[SP.City])
    )
    ),
    NetworkData[SP.City] & " (" & [@VisitCount] & ")",
    " | ",
    NetworkData[SP.City],
    ASC
    ),
    REMOVEFILTERS(NetworkData),
    NetworkData[UserEmail] = EmployeeEmail,
    NetworkData[SP.City] <> OfficeCity
    )

    RETURN
    IF(
    NOT ISBLANK(EmployeeEmail)
    && NOT ISBLANK(OfficeCity)
    && IsEmployeeInLocation > 0,

    IF(
    HasOfficeVisit > 0,
    IF(
    ISBLANK(OtherCities),
    OfficeCityWithCount,
    OfficeCityWithCount & " | " & OtherCities
    ),
    ""
    ),
    BLANK()
    )

  • Hey Swami_om ,

    upload a PBIX file to OneDrive or Dropbox, that contains sample data but besides represents your semantic model (realtionships, calculated columns, and measures).

    Next to that describe the expected outcome based on the sample data you provided.

    Regards,
    Tom

  • Hi Swami_om,

    Checking in to see if your issue has been resolved. let us know if you still need any assistance.

     

    Thank you.