Forum Discussion

Diego_Vialle's avatar
Diego_Vialle
Helper II
4 years ago

Custom Column in Power Query

I have a measure created in DAX to demonstrate:
Customers who have never purchased, but have purchased within the last two months.


I would like a custom column in Power Query with this rule, it can be a boolean column. Here is the DAX formula used:

 

Frequencia pedidos Bimestral =
VAR AllOldCustomers =
CALCULATETABLE (
VALUES ( SBOPRODMS[Nome do PN] ),
SBOPRODMS,
SBOPRODMS[Data NF]
< TODAY () - 60,
SBOPRODMS[Documento] = "Nota fiscal de saída"
)
VAR AllNewCustomers =
CALCULATETABLE (
VALUES ( SBOPRODMS[Nome do PN] ),
SBOPRODMS[Data NF]
< TODAY () ,
SBOPRODMS[Documento] = "Nota fiscal de saída"
)
RETURN
COUNTROWS ( EXCEPT ( AllNewCustomers, AllOldCustomers ) )

8 Replies

Replies have been turned off for this discussion
  • Anonymous's avatar
    Anonymous
    Not applicable

    if you explain where you are starting from and what you want to achieve, even those unfamiliar with DAX can look for a solution

    • Diego_Vialle's avatar
      Diego_Vialle
      Helper II

      I demonstrated the formula in DAX because I thought it would make it easier to understand. But no problem.

      I need a column that brings me customers who have never purchased but have purchased in the last two months.

      I have the following columns to filter:
      [NP Name]
      [Invoice Date]
      [Document] = "A/R Invoice"

      • Anonymous's avatar
        Anonymous
        Not applicable

        it may be that I, in addition to the DAX, have problems with English. I can't understand what you mean by customers who have never purchased but have purchased in the last couple of months.

         

        Se l'intenzione è quella di trovare i clienti che hanno comprato SOLO negli ultimi due mesi ma non hanno comprato mai prima, devi fare un table.group sulla colonna [NP Name], poi controlli se la data minima di ogni gruppo ricade negli ultimi due mesi (vedi l'istruzione sotto.).

        Se vuoi lo script completo, posta delle tabelle (anche fittizie) con i dati minimi che serveno per trattare tutte le casistiche che ti ritrovi in relatà.

         

        Date.IsInPreviousNMonths([invoicedate],2))

         

         

  • wdx223_Daniel's avatar
    wdx223_Daniel
    Community Champion

    NewStep=let a=Date.AddDays(DateTime.LocalNow(),-60),b=List.Buffer(List.Accumulate(Table.ToRecords(PrivousStepName),{{},{}},(x,y)=>if y[Documento]="Nota fiscal de saída" and y[Data NF]<a then {List.RemoveItems(x{0},{y[Nome do PN]}),x{1}&{y[Nome do PN]}} else if List.Contains(x{1},y[Nome do PN]) then x else {x{0}&{y[Nome do PN]},x{1}}){0}) in Table.AddColumn(PrivousStepName,"CustomColumn",each List.Contains(b,[Nome do PN]))

    • Diego_Vialle's avatar
      Diego_Vialle
      Helper II

      I didn't understand what to insert in Previous Step Name:

       

       

      • AlexisOlson's avatar
        AlexisOlson
        Super User

        The previous step's name is Columnas Renomeadas2, so you'd use write #"Columnas Renomeadas2" instead of PreviousStepName.