Forum Discussion

aashton's avatar
aashton
Icon for Helper V rankHelper V
4 years ago
Solved

Problem with joining tables and filters

Hello,

I have a job posting table and a location table, linked on Location ID.  I  have a couple measures, one on Job Posting table, total Postings, and one on the Location table, total Staffing, and use Total Postings/Total Staffing to find another measure.   I need to filter out locations that are less than a year old.  If I create the column on the Location table to find new locations, and use this to filter, it filters the Locations table (thus reducing the Total Staffing measure), but it also removes all Job Postings that do no link to the Locations table.  I want to keep all Job Postings that do not link to the Locations table in the Total Postings count.  So I then created a left join on the Location table and added the New/Existing flag into the Job Postings table.  But now when I fitler on this, it reduces the Total Postings but does not filter the Total Staffing on the Locations table.

Any idea how I can filter out new locations, but keeps all job postings that do not link(exist) in the Locations table?

  • aashton well then make small tweak and you will be good to go:

    Total FTEStatus = SUM(JobRequisitions[FTEStatus]) +
    IF ( ISFILTERED ( 'CRM Sharepoint'[New/Existing Column] ),
    CALCULATE (sum(JobRequisitions[FTEStatus]), REMOVEFILTERS ('CRM Sharepoint'), KEEPFILTERS (JobRequisitions[Location_Identifier] = "NULL" ) )
    , 0 
    )

14 Replies

  • aashton replace countrows with whatever summarization you want to use, sum ( Table[Column Name] )

    The core logic is going to be the same.

     

    Follow us on LinkedIn and  to our YouTube channel

    I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

    • aashton's avatar
      aashton
      Icon for Helper V rankHelper V

      So I've changed it to this:

      Total FTEStatus = SUM(JobRequisitions[FTEStatus]) + CALCULATE (sum(JobRequisitions[FTEStatus]), REMOVEFILTERS ('CRM Sharepoint'), KEEPFILTERS (JobRequisitions[Location_Identifier] = "NULL" ) )
       
      I think it's doing something with rounding, because the sum is not coming out correct even though I am getting the correct records.    I think it's making the .95, .9, .8 etc as 1.
  • aashton well then make small tweak and you will be good to go:

    Total FTEStatus = SUM(JobRequisitions[FTEStatus]) +
    IF ( ISFILTERED ( 'CRM Sharepoint'[New/Existing Column] ),
    CALCULATE (sum(JobRequisitions[FTEStatus]), REMOVEFILTERS ('CRM Sharepoint'), KEEPFILTERS (JobRequisitions[Location_Identifier] = "NULL" ) )
    , 0 
    )
    • aashton's avatar
      aashton
      Icon for Helper V rankHelper V

      Can I ask one more scenario?  What if a job posting does have a Location Identifier, but it does not exist in the Locations table, there is no match?  How can I include these?

  • aashton can you share sample data and how these tables are related and the expected output? 

    • aashton's avatar
      aashton
      Icon for Helper V rankHelper V

      Job Posting table:

      Location_IdentifierRTRFTEStatus
      NULLJR33911
      NULLJR33941
      NULLJR33951
      NULLJR33961
      NULLJR33971
      NULLJR33981
      NULLJR33991
      NULLJR34131
      NULLJR34141
      NULLJR34151
      NULLJR34161
      NULLJR34181
      AA185971
      AAJR16961
      CT110262161
      CT110273931
      CT110273941
      CT1102JR17721
      CT1102JR34781
      CT1138JR20091
       Total FTEStatus20

       

      Location Table

      Location_IdentifierTotal Staffing ModelNew/Existing
      CT110220Existing
      CT113850New
      Total Staffing Model70 

      If I want to filter on New/Existing, and only include Existing, I will remove CT1138 and the 50 from the Total Staffing Model, and the Job Posting for CT1138 of 1 for a total of 19 FTEStatus.   But when I filter on only existing, it also removes those 12 that do not exist in the Location table.  I do not want to remove these 12 from the total FTEStatus.

  • aashton so you want to keep the location identifier which is null regardless of what you filter on location table, correct?

    • aashton's avatar
      aashton
      Icon for Helper V rankHelper V

      Thank you, but the FTEStatus per job does not always equal 1, it could be .5, .8.  So the total rows does not always equal the total FTEStatus.

  • aashton here is the measure which will do it:

     

    Job Posting Count = 
    COUNTROWS ( JobPosting ) + 
    CALCULATE ( 
        COUNTROWS ( JobPosting ), 
        REMOVEFILTERS ( Location ), 
        KEEPFILTERS ( JobPosting[Location_Identifier] = "NULL" ) 
    )

     

    Follow us on LinkedIn and  to our YouTube channel

    I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

  • aashton make sure measure format is set to decimal, select the measure and check the format, and if required, change it to decimal

     

     

    Follow us on LinkedIn and  to our YouTube channel

    I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

     

     

    • aashton's avatar
      aashton
      Icon for Helper V rankHelper V

      Yes, thank you so much that works.  But now I'm thinking, if I let the users change the filters, they can change from existing to new, and it will still work.  But if they remove the filter and want to see all of them, the total FTEStatus will be too high....because it will add the total FTEStatus, but then add the ones missing the Location Identifiers in again....

  • aashton the most logical sense is to fill the missing location id's in the location table rather than juggling with DAX, again you can always write a complex DAX or you make your data ready that is ready to consume and have less juggling the DAX. I would recommend 2nd option in this case, although DAX can achieve what you are looking for, it is overkill.

     

    This is how I will approach it.