Forum Discussion

Mike1309's avatar
Mike1309
Frequent Visitor
2 years ago
Solved

Data grouping based on second table

Dear Experts, I'm looking for a solution to a problem I cannot deal with  I have two tables: Periods:    and invoices:   every period for every country is different Based on countr...
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi Mike1309

     

    I have understood about your problem, here is the solution I offer:

     

    Here are the data of the two tables, you can check the date type, here it is recommended to use the (m/d/yyyy) format

     

    Create a  measure, you can match the period by judging the country name and date range.

     

     

    result = var invoiceDate = SELECTEDVALUE(invoices[invoice date])
     var invoiceCountry = SELECTEDVALUE(invoices[country])
    
     RETURN CALCULATE(
            MAX(periods[period]),
        FILTER(periods, 
            periods[country] = invoiceCountry && 
            periods[start day] <= invoiceDate &&
            periods[end day] >= invoiceDate))

     

     

    Here is the result, and you can add slicers to filter

    Best Regards,

    Nono Chen

    If this post helps, then please consider Accept it as the solution  to help the other members find it more quickly.