Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
Hello.
I made a python script and it runs in power query, it returns one date and one float column. When I try to change column types according to their values, they change. Changing the column type also changes the values in the same column. Here an example.
This is what returns python script.
I try to change the type of date column to date type and and the values in the prediction column change.
In report view the values are also different from those shown in power query.
In the python script, a model is created with neural networks from the keras library and returns the predictions of the initial data. I believe is due to keras, how can I avoid this?
I appreciate any help. Thank you for your ideas and time.
what happens if in the step before you do a the change type if you wrap it in a Table.Buffer() function? Just put Table.Buffer() around the entire line, and then change the type to Date.
DAX is for Analysis. Power Query is for Data Modeling
Proud to be a Super User!
MCSA: BI ReportingHi.
I tried what you said but that also change the values.
Hi @inm ,
Could you please consider sharing a sample file without any sesentive information or the sample python script query code for further discussion?
Best Regards,
Community Support Team _ Yingjie Li
Python script:
import pandas as pd
import numpy as np
from keras.layers import Dense, LSTM
from keras.models import Sequential
from keras.preprocessing.sequence import TimeseriesGenerator
def get_prediction_dates(num_prediction, df):
last_date = df['date'].max()
date_test = pd.date_range(last_date, periods=num_prediction+1, freq='M').to_frame(index=False, name='date')
date_test = date_test['date'].apply(lambda x : x.replace(day=1))
return date_test
def predict(num_prediction, model):
prediction_list = arr[-look_back:]
for _ in range(num_prediction):
x = prediction_list[-look_back:]
x = x.reshape((1, look_back, 1))
out = model.predict(x)[0][0]
prediction_list = np.append(prediction_list, out)
prediction_list = prediction_list[look_back-1:]
return prediction_list
look_back = 12
batch_size = 4
arr = dataset['quantity'].values
arr = arr.reshape((-1, 1))
generator = TimeseriesGenerator(arr, arr, length=look_back, batch_size = batch_size)
model = Sequential()
model.add(
LSTM(128,
activation='linear',
input_shape=(look_back, 1),
name="LSTM")
)
model.add(Dense(1, activation='linear', name="Dense"))
model.compile(optimizer='adam', loss='mse', metrics=['mean_absolute_percentage_error'])
model.fit(generator, epochs=70)
num_prediction = 6
forecast = predict(num_prediction, model)
forecast_dates = get_prediction_dates(num_prediction, dataset)
dataset = pd.DataFrame(list(zip(forecast_dates, forecast)), columns=['date', 'prediction'])
dataset['date'] = pd.to_datetime(dataset['date'])
I placed a seed, but is there any other way to prevent this from happening?
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 19 | |
| 9 | |
| 8 | |
| 7 | |
| 6 |