Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Olá,
Preciso criar um novo campo a partir de uma somases, que respeite o Cod Centro e o mês, mas sem especificar entre ' ' os valores.
Obrigado.
@julianoguerra
Experimente utilizar o qualificador total, você pode estar definindo as dimensões a qual quer totalizar entre os sinais de menor e maior < >.
Então seria algo assim:
sum(total<[Mês/Ano],[Cod Centro]>[Qtde Total])
- Matheus
Hello,
You want to create a new field in your data based on a sum of cases, while grouping by Center Code and month, but without using single quotes for values. Assuming you're working with SQL or a similar query language, here's a general approach to achieve that:
SQL Approach
If you're using SQL, you can achieve this with a GROUP BY clause and SUM function. Here's a basic example: SELECT
CenterCode,
MONTH(DateColumn) AS Month,
SUM(Cases) AS TotalCases
FROM
YourTable
GROUP BY
CenterCode,
MONTH(DateColumn);
In Other Query Languages
For languages or tools like DAX in Power BI, or pandas in Python, the approach will vary slightly. Here’s how you might do it:
DAX (Power BI) NewField =
SUMX(
FILTER(
YourTable,
YourTable[CenterCode] = EARLIER(YourTable[CenterCode]) &&
MONTH(YourTable[DateColumn]) = EARLIER(MONTH(YourTable[DateColumn]))
),
YourTable[Cases]
) Pandas (Python)
import pandas as pd
# Assuming df is your DataFrame
df['Month'] = df['DateColumn'].dt.month
result = df.groupby(['CenterCode', 'Month'])['Cases'].sum().reset_index()
result.rename(columns={'Cases': 'TotalCases'}, inplace=True)
Hope that helps!